存储散列的电子邮件通常会很痛苦,而且通常不是必需的,尽管它取决于您的站点/功能/服务等。即具有一定安全级别要求的政府站点可能希望对电子邮件地址进行加密,因为它们可能是高级理事会官员(ETC)。这确实取决于个人情况。
密码 - 永远不要以纯文本形式存储。即使为您自己的站点管理员或其他任何东西进行自己的小登录,做正确的事情也是一个好习惯,另外这将帮助您学习并生成可以在其他站点/项目上重复使用的模板代码。
如果您显示您的登录代码,我们可以看看。
在任何用户输入代码上,您都应该验证数据是可接受的以及您所期望的。即使是您自己的登录区域,虽然您显然不会入侵自己,但正确地做事并再次为您提供公共区域的模板代码(而且您永远不知道谁可以访问您的登录区域)仍然是一种很好的做法。使用 PHP 函数如 strlen()、is_numeric() 和一些正则表达式来检查输入数据是否正常(即最大或最小字符长度,只能输入数字或字母数字等)。这也用于维护数据库,就像您有一个 varchar(20) 列一样,使用 strlen 检查用户输入是否为 20 也可以避免任何数据库问题。
由于您已经在使用 MYSQLI,我建议您研究一下 crypt blowfish,它非常简单,是一种现代的安全方式来存储和检索密码。
一个非常基本的使用地穴和河豚的介绍:
require('PasswordHash.php');//you download this file, and just include it
//it contains all the hashing engine etc
// $PostPassword is the one they entered in a form (etc)
$CreateHash = new PasswordHash(8, FALSE);
$HashPassword = $CreateHash->HashPassword($PostPassword);
// $HashPassword is the hashed and salted password you store in the db
// (should always be 60 chars, check with strlen)
// Don't use your own salt, it's not worth it
// and you end up having to use it/store it/remember it
// when checking their password for login etc.
// just use the built in blowfish random salting algos
// Then to check their pass (ie login)
// Query and select their password from DB ($DbPass)
// with their username entered in the login form
// Check it against the password they entered in form
// (CheckPassword salts/hashes automatically to match the DB one)
$CreateHash = new PasswordHash(8, FALSE);
$CheckPass = $CreateHash->CheckPassword($PostPassword, $DbPass);
if ($CheckPass)
{
// password matches
}
else
{
//not match, tell them to try again etc
}
// you can use various checks on this, mainly check if the
// library exists (to avoid php errors etc)
if(defined("CRYPT_BLOWFISH") && CRYPT_BLOWFISH)
{
// do all your password stuff
}
在执行上述操作之前,您需要进行其他检查,例如 strlen 等,然后一旦您对数据有效,您就可以将其存储在数据库中。
您还应该在数据库查询中使用准备好的语句,因为这是一种非常安全的方法。