Checking md5 password from Mysql
| From: | Dennis Martin Ong | Date: | Wed, 16 Apr 2003 19:10:22 +0000 |
| Subject: | Checking md5 password from Mysql | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144181@lists.php.net to get a copy of this message | ||
Hi,
Can anyone point out where to change this code to anthenticate the password
which is "encrypted" using md5 in MySql? The code works for password not
stored using md5. Btw, the code is generated by Dreamweaver MX's PHP Server
extension, using the User Authentication extension made by someone else.
Thanks in advance.
Dennis
(I'm a complete newbie to PHP, so pls bear with me)
<?php require_once('Connections/connUser.php'); ?>
<?php
mysql_select_db($database_connUser, $connUser);
$query_Recordset1 = "SELECT * FROM
user";
$Recordset1 = mysql_query($query_Recordset1, $connUser) or
die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
// *** Start the session
session_start();
// *** Validate request to log in to this site.
$FF_LoginAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING']) &&
$HTTP_SERVER_VARS['QUERY_STRING']!="") $FF_LoginAction .=
"?".$HTTP_SERVER_VARS['QUERY_STRING'];
if (isset($HTTP_POST_VARS['textfield'])) {
$FF_valUsername=$HTTP_POST_VARS['textfield'];
$FF_valPassword=$HTTP_POST_VARS['textfield2'];
$FF_fldUserAuthorization="";
$FF_redirectLoginSuccess="success.php";
$FF_redirectLoginFailed="failed.php";
$FF_rsUser_Source="SELECT user_name, user_password ";
if ($FF_fldUserAuthorization != "") $FF_rsUser_Source .= "," .
$FF_fldUserAuthorization;
$FF_rsUser_Source .= " FROM user WHERE user_name='" . $FF_valUsername .
"'
AND user_password='" . $FF_valPassword . "'";
mysql_select_db($database_connUser, $connUser);
$FF_rsUser=mysql_query($FF_rsUser_Source, $connUser) or
die(mysql_error());
$row_FF_rsUser = mysql_fetch_assoc($FF_rsUser);
if(mysql_num_rows($FF_rsUser) > 0) {
// username and password match - this is a valid user
$MM_Username=$FF_valUsername;
session_register("MM_Username");
if ($FF_fldUserAuthorization != "") {
$MM_UserAuthorization=$row_FF_rsUser[$FF_fldUserAuthorization];
} else {
$MM_UserAuthorization="";
}
session_register("MM_UserAuthorization");
if (isset($accessdenied) && true) {
$FF_redirectLoginSuccess = $accessdenied;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = false;
header ("Location: $FF_redirectLoginSuccess");
exit;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = true;
header ("Location: $FF_redirectLoginFailed");
exit;
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo $FF_LoginAction?>" method="POST"
enctype="application/x-www-form-urlencoded" name="form1">
<p>
<label>User Name
<input type="text" name="textfield">
</label>
</p>
<p>
<label>Password
<input type="password" name="textfield2">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>