我看到哈希和加密算法之间存在很多混淆,我希望听到一些更专业的建议:
何时使用哈希与加密
什么使哈希或加密算法不同(从理论/数学水平),即什么使哈希不可逆(没有彩虹树的帮助)
以下是一些类似的 SO问题,没有像我想要的那样详细说明:
我有这个加密密码的脚本,但我不知道如何反转它并解密它.这可能是一个非常简单的答案,但我不明白该怎么做.
#!/usr/bin/perl
use Crypt::Eksblowfish::Bcrypt;
use Crypt::Random;
$password = 'bigtest';
$encrypted = encrypt_password($password);
print "$password is encrypted as $encrypted\n";
print "Yes the password is $password\n" if check_password($password, $encrypted);
print "No the password is not smalltest\n" if !check_password('smalltest', $encrypted);
# Encrypt a password
sub encrypt_password {
my $password = shift;
# Generate a salt if one is not passed
my $salt = shift || salt();
# Set the cost to 8 and append a NUL
my $settings = '$2a$08$'.$salt;
# Encrypt it …Run Code Online (Sandbox Code Playgroud) 如何在Laravel中从给定请求验证用户密码?如何根据存储在数据库中的密码哈希检查密码?
我可以通过迁移在数据库中创建第一条记录吗,其中password列中的第一条记录已经被加密
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email');
$table->string('level');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
User::firstOrCreate([
'name' => 'admin',
'email' => 'admin@app.com',
'level' => 'Administrator',
'password' => 'password'
]);
}
Run Code Online (Sandbox Code Playgroud)
代码可以工作,但未password加密,有什么建议吗?
我想定制我的登录界面,在laravel 4,其中username要么是他username还是email那么我所做的是:
public static function custom_login($uname,$pwd)
{
$res = DB::select("select * from users where (username = ? or email = ?) and password = ? and active = 1",array($uname,$uname,$pwd));
return $res;
}
Run Code Online (Sandbox Code Playgroud)
现在,我们都知道密码是哈希的,所以你无法使用password = ?.如果密码正确,我怎么检查密码?