我在哪里把password_verify函数放在我的代码中?

时间:2014-07-08 16:28:26

标签: php

我正在处理登录表单。我已经使用password_hash函数完成了我的注册表单,并以这种方式成功地将所有密码保存在我的数据库中。

我不知道我将把passwod_verify函数放在哪里以及我必须准确编码验证以便将普通的txt密码与散列版本进行比较? 我知道我需要将这个问题分成两部分: 1)检查用户名后,从我的数据库中获取hashedpassword。 2)将其与用户输入密码进行比较,以验证并允许用户登录。

我的代码在下面,也是我数据库的一部分。

![我的数据库内容] [1]

  <?php require_once('Connections/bankusers.php'); ?>
<?php session_start(); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['UserName'])) {
$loginUsername=$_POST['UserName'];
$password=$_POST['Password:'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "loginusermemo.php";
$MM_redirectLoginFailed = "loginuser.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_bankusers, $bankusers);
$LoginRS__query=sprintf("SELECT UserID, Password FROM users WHERE UserID=%s AND Password=%s",
GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $bankusers) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Login User</title>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" href="style/style.css" title="style" />
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<div id="header">
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1><a href="index.php">ModelOnline<span class="logo_colour">Bank</span></a></h1>
<h2>Your. Bank. On. Demand.</h2>
</div>
</div>
<div id="menubar">
<ul id="menu">
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li class="selected"><a href="index.php">Home</a></li>
<li><a href="register.php">REGISTER</a></li>
<li><a href="login.php">lOGIN</a></li>
<li><a href="aboutus.php">ABOUT US</a></li>
<li><a href="contactus.php">Contact Us</a></li>
<li><a href="accessibility.php">Accessibility</a></li>
<li><a href="security.php">Security</a></li>
</ul>
</div>
</div> <div align="center" class="bankservices"><a href="http://www.modelonlinebank.com/bankproducts.php#one">Current Accounts</a> | <a href="http://www.modelonlinebank.com/bankproducts.php#two">Savings Accounts</a> | <a href="http://www.modelonlinebank.com/bankproducts.php#three">Mortgages</a> | <a href="http://www.modelonlinebank.com/bankproducts.php#four">Insurance</a> | <a href="http://www.modelonlinebank.com/bankproducts.php#five">Credit Cards</a> | <a href="http://www.modelonlinebank.com/bankproducts.php#six">Investments</a></div>
<div id="site_content">
<div class="sidebar">
<!-- insert your sidebar items here -->
<h3>Latest News</h3>
<h4>Personal Banking</h4>
<h5>January 1st, 2014</h5>
<p>Current Accounts,Saving Accounts,Range of Credit And Debit cards to suit all your needs. We have your interest in mind.<br />
<a href="#">Read more</a></p>
<p></p>
<h4>Corporate Banking</h4>
<h5>February 5th, 2014</h5>
<p>We help you achieve your goals by providing numerous funding options.Provide Risk management of your finances and look for strategic and finance options to promote business.<br /><a href="#">Read more</a></p>
<h3>Useful Links</h3>
<ul>
<li><a href="#">Credit card</a></li>
<li><a href="#">Debit card</a></li>
<li><a href="#">Loans</a></li>
<li><a href="#">Insurance</a></li>
</ul>
<h3>Search</h3>
<form method="post" action="#" id="search_form">
<p>
<input class="search" type="text" name="search_field" value="Enter keywords....." />
<input name="search" type="image" style="border: 0; margin: 0 0 -9px 5px;" src="style/search.png" alt="Search" title="Search" />
</p>
</form>
</div>
<div id="content">
<!-- insert the page content here -->
<h1>Login Part 1 of 2</h1>
<p>Please kindly Input your Account Number and Password below:</p>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="loginform" id="loginform">
<table width="500" border="0">
<tr>
<td><span id="sprytextfield1">
<label for="UserName"></label>
Account Number: <br>
<input type="text" name="UserName" id="UserName">
<span class="textfieldRequiredMsg">Enter Your Account Number.</span></span></td>
</tr>
<tr>
<td><span id="sprytextfield2">
<label for="Password:"></label>
Password: <br>
<input type="password" name="Password:" id="Password:">
<span class="textfieldRequiredMsg">Enter Your Password.</span></span></td>
</tr>
<tr>
<td><input type="submit" name="LoginButton" id="LoginButton" value="Login"></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
</div>
<div id="content_footer"></div>
<div id="footer">
&copy;Modelonlinebank 2014 | <a href="#sitemap">SiteMaP</a> | <a href="#privacy">Privacy</a> | <a href="#jobs">Jobs</a> | <a href="#terms">Terms</a> | <a href="contactus.php">Feedback</a></div>
</div>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我将忽略此表单的安全性,只关注您的要求。你需要改变

$password=$_POST['Password:'];

对此(假设您只在数据库中存储md5哈希):

$password=md5($_POST['Password:']);