md5 hash login with php and mysql

2019-09-08 07:01发布

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)

3条回答
一纸荒年 Trace。
2楼-- · 2019-09-08 07:34

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
    }
查看更多
Lonely孤独者°
3楼-- · 2019-09-08 07:44

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!'
}
查看更多
Evening l夕情丶
4楼-- · 2019-09-08 07:48

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.

查看更多
登录 后发表回答