[英]how to change my md5 to a hashed password in php
My teacher wants to change my md5 password that was already made to a hashed one.我的老师想将我已经设置的 md5 密码更改为散列密码。 I tried to use hashed but I cant login.我尝试使用散列但我无法登录。 I'm new with coding and I'm really confused on why I can't login.我是编码新手,我真的很困惑为什么我无法登录。
This is my Sign Up page:这是我的注册页面:
<?php
if(isset($_POST['btnCreate'])){
$Aboutme = "This portion is about what can baby sitter tell about themselves to attract Parents/Guardian.";
$txtName = trim($_POST['txtName']);
$cboType = trim($_POST['cboType']);
$txtUser = trim($_POST['txtUser']);
$pwPass = $_POST['pwPass'];
$pass = password_hash($pwPass, PASSWORD_DEFAULT);
$exist = DB::query("SELECT * FROM user WHERE u_username=?",array($txtUser),"READ");
if (count($exist)>0){
error('Username already exist!');
} else {
if($cboType == "Sitter"){
DB::query("INSERT INTO user(u_type, u_name, u_aboutme, u_username, u_password, u_hires) VALUES(?,?,?,?,?,?)",array($cboType, $txtName, $Aboutme, $txtUser, $pass,0),"CREATE");
}
else {
DB::query("INSERT INTO user(u_type, u_name, u_username, u_password, u_hires) VALUES(?,?,?,?,?)",array($cboType, $txtName, $txtUser, $pass,0),"CREATE");
}
$exist_id = DB::query("SELECT * FROM user WHERE u_username=?",array($txtUser),"READ");
if (count($exist_id)>0){
$exist_id = $exist_id[0];
DB::query("INSERT INTO subs(u_id) VALUES(?)",array($exist_id['u_id']),"CREATE");
}
success('Successfully created an account!');
This is my login page:这是我的登录页面:
$txtUser = "";
$pwPass = "";
loginUser('btnLogin', 'txtUser', 'pwPass');
?>
<label>Username</label>
<input type="text" name="txtUser" required>
<label>Password</label>
<input type="password" name="pwPass" required>
<button type="submit" name="btnLogin">Log In</button>
<a href="create.php">Create</a>
</form>
</div>
<div class="a-div">
<a href="forgotpass.php">Forgot Password?</a>
</div>
you cannot login with the old password since it uses different hashing algorithme and it is impossible to decrypt, you can only compare it against a plain text password.您无法使用旧密码登录,因为它使用不同的哈希算法并且无法解密,您只能将其与纯文本密码进行比较。
there are two things to bare in mind:有两件事要记住:
$pwPass = trim($_POST['pwPass']);
您也需要修剪密码$pwPass = trim($_POST['pwPass']);
password_verify($password, $hashedpassword);
你应该使用password_verify($password, $hashedpassword);
in your loginUser.在您的登录用户中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.