md5 hash login with php and mysql

扶醉桌前 提交于 2020-02-07 04:49:08

问题


I was given an excel file with about 450 username and passwords (the passwords are encoded with MD5 hash) How can I put this excel (.xls) file into my MySQL database and on the website (php side) how can I check if the user entered password is the correct password (I know nothing about hashing a password with MD5 or any hash-sequence for that matter)


回答1:


1.- You can export an excel file as a CSV file.
2.- Use phpmyadmin to import to your site a CSV file.
3.- Checking passwords:

if (md5($_POST['user_password']) == $db['user_password'])
{
    echo 'welcome back bro!'
}



回答2:


the md5 password may be "salted" to provide extra security.

If not salted:

  • ?php md5(ClearTextPassord) == $passwordInExcel

If salt, this salt may etiher be global (same for all accounts), or partly individual, (some account-data is provided when calculationg the hash.

Example:

  • Global: <?php md5(onceTypedPassword . $globalSalt)
  • Global and individual: <?php oncedTypedPassword . $globalSalt . $userRec['Firstname'])
  • ..other ways are possible..

If hash is salted you NEED the salt.




回答3:


http://www.ibm.com/developerworks/opensource/library/os-phpexcel/ will help you with storing the passwords from the excel file to the mysql database, and md5 documentation is pretty helpful.

You can fetch the password for a given username from the db and check with something like this:

$username = mysql_real_escape_string( $username_user_gave )
$query = "SELECT * FROM users WHERE username = '$username' LIMIT 1;";
$result = mysql_query( $query ) or die('Could not perform query');
if( mysql_affected_rows != 1 ){
    // user not found
    }
$row = mysql_fetch_array( $result );
$stored_password = $row['password'];
$given_password = md5( $password_user_gave );
if( $stored_password == $given_password ){
    //everything ok
    }
else{
    //incorrect password
    }


来源:https://stackoverflow.com/questions/9343807/md5-hash-login-with-php-and-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!