简体   繁体   中英

Newbie php question with hashing passwords and user login

Here is my create account mysql query. For the sake of ease I have left out salting.

$q = $dbc -> prepare("INSERT INTO accounts (username, email, password) 
                      VALUES (?, ?, ?)");
$q -> execute(array($_POST['username'], $_POST['email']
                        ,hash('sha256', $_POST['password'])));

Which does what I want, inserts a hashed password into the database, now my login script;

if ($count == 1 && $info['password'] === hash('sha256', $_POST['password']) 
                && $info['logcount'] != -1) { // successful login

This statement always returns false, I have tried different operates ie (=, ==), I am sure it is a simple solution.

Also if you have any good salting techniques please share :)

Thanks.

Why do you make type checking with ===? Maybe just

$info['password'] == hash('sha256', $_POST['password'])

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM