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
}