[英]How to show hashed password
我已经成功地对用户在我的网站上注册的密码进行了散列处理,并通过使用密码验证功能,我可以根据散列的密码检查他们的原始密码并允许他们登录。 但是在他们的我的帐户页面上,我希望他们看到他们的原始密码,但它在我的帐户页面中显示了散列密码。 在我的帐户页面上是否有将散列密码转换为其原始密码的功能?
我已成功散列用户在我的网站上注册的密码并使用密码验证功能
好 那你问
我希望他们看到他们的原始密码,但它在我的帐户页面中显示了散列密码。 在我的帐户页面上是否有将散列密码转换为其原始密码的功能?
不,你不能这样做,否则它会破坏散列的整个目的。
所以换句话说,用户不能更新他们的密码对吗? 因为我也有更新信息页面
为了能够更新他们的密码,他们不需要看到它,他们只需要知道它。
通常无法检索散列密码(这取决于散列函数,无法检索安全散列)。 如果它们在两个站点上具有相同的哈希值,则它们可能具有相同的密码,这取决于站点使用的哈希值、使用什么方法等。
无法获得散列密码。 如果您希望用户通过确认旧密码来更新密码,请将旧密码与新密码一起作为输入条目,并将其哈希值与存储在数据库中的值进行比较。 如果旧密码的哈希值与数据库中的哈希值相同,则允许用户更新密码。 否则提醒旧密码错误
md5
和sha1
是一种方式,可能是您正在使用的其中一种方式(只是猜测)。 如果您需要两种方式,您可以简单地使用mcrypt_encrypt
和mcrypt_decrypt
。
但是,我不建议您向用户显示密码:-
对于更改密码:您可以简单地询问用户他们的旧密码和新密码,对其进行加密并与存储数据库中的加密密码匹配,如果匹配,则为相应用户更新数据库中的新加密密码。
对于忘记密码:您可以为该特定用户生成一个令牌,并将其与链接(重置密码)一起作为参数发送到他们所需的电子邮件地址,当他们使用该链接时,您将获得令牌以验证和存储新的加密数据库中的密码。
如果您想使用管理面板查看密码,则不需要对密码进行哈希处理。 只需使用 openssl_encypt() 函数加密密码,然后查看密码,您可以使用 openssl_decypt() 函数..
//您可以使用以下代码...
<?php
// Store a string into the variable which
// need to be Encrypted
$simple_string = "Welcome to Sidedevelopers";
// Display the original string
echo "Original String: " . $simple_string . "\n";
// Store cipher method
$ciphering = "BF-CBC";
// Use OpenSSl encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
// Use random_bytes() function which gives
// randomly 16 digit values
$encryption_iv = random_bytes($iv_length);
// Alternatively, we can use any 16 digit
// characters or numeric for iv
$encryption_key = openssl_digest(php_uname(), 'MD5', TRUE);
// Encryption of string process starts
$encryption = openssl_encrypt($simple_string, $ciphering,
$encryption_key, $options, $encryption_iv);
// Display the encrypted string
echo "Encrypted String: " . $encryption . "\n";
// Decryption of string process starts
// Used random_bytes() which gives randomly
// 16 digit values
$decryption_iv = random_bytes($iv_length);
// Store the decryption key
$decryption_key = openssl_digest(php_uname(), 'MD5', TRUE);
// Descrypt the string
$decryption = openssl_decrypt ($encryption, $ciphering,
$decryption_key, $options, $encryption_iv);
// Display the decrypted string
echo "Decrypted String: " . $decryption;
?>
输出:
原始字符串:欢迎使用 Sidedevelopers
加密字符串:hwB1K5NkfcIzkLTWQeQfHLNg5FlyX3PNUA==
解密字符串:欢迎来到 Sidedevelopers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.