php修改密码功能md5,php – 更改密码哈希类型的最有效方法(md5到sha1)

您无法将md5转换为sha,但实际上您的用户在登录时只使用密码,因此您可以稍微修改脚本以自动执行更新

// The user is not authticated yet

$auth = false;

$updated = false;

// From your Login form

$user = $_POST['user'];

$pass = $_POST['pass'];

// Check If the username has update password

$udated = false; // not update

// I gues you always do this

$password = $updated ? md5($pass) : sha1($pass);

// Do the autentication

// Slect from Database

// Check the data

// Set auth

$auth = true;

// Then chage the password

if ($auth == true && !$updated) {

$newpassword = sha1($pass);

// Connect to DB

// Update the Password

// Set Status to Updated in DB

$udated = true;

}

// Better Approch

if ($auth == true && !$updated) {

$newpassword = password_hash($password, PASSWORD_BCRYPT);

// Connect to DB

// Update the Password

// Set Status to Updated in DB

$updated = true;

}

我使用password_hash有一个更好的方法,因为它使用BCRYPT这是一个更好的哈希算法. See more information on password_compat

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值