简体   繁体   中英

PHP Password Hashing

As of now I have this line of code

<?php
    $pass = "12312312";
    echo md5(crypt($pass))
?>

I know crypt can randomly generate salt but I don't have any idea how can I compare it on the user input.

What are the fields do I need for my log in table? and also, what data will I insert to my table?

thanks!

You can store password in table as below

$pass = "12312312";

// store this in table with separate column
$salt = md5("any variable"); // may be email or username

// generate password
$password = sha1($salt.$pass);

// now store salt and password in table

And you can check password like

$pass = "User input";

// get the user from database based on user id or username
// and test the password stored in db with

if($passwordFromTable == sha1($saltFromTable.$pass))
{
    // correct
}

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