refactor(auth): upgrade password hashing to PHP's password_hash
- Replace custom password hashing function with PHP's built-in password_hash - Update password verification to use password_verify - Adjust database schema to accommodate new password hash length - Modify installation and login controllers to use new hashing method
This commit is contained in:
@@ -109,7 +109,7 @@ class Index extends AdminController
|
||||
|
||||
try {
|
||||
$save = $row->save([
|
||||
'password' => password($post['password']),
|
||||
'password' => password_hash($post['password'], PASSWORD_DEFAULT),
|
||||
]);
|
||||
}catch (Exception $e) {
|
||||
$this->error('保存失败');
|
||||
|
||||
@@ -53,7 +53,7 @@ class Login extends AdminController
|
||||
if (empty($admin)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
if (password($post['password']) != $admin->password) {
|
||||
if (!password_verify($post['password'], $admin->password)) {
|
||||
$this->error('密码输入有误');
|
||||
}
|
||||
if ($admin->status == 0) {
|
||||
|
||||
@@ -105,12 +105,12 @@ class Install extends BaseController
|
||||
foreach ($sqlArray as $sql) {
|
||||
$pdo->query($sql);
|
||||
}
|
||||
$_password = password($password);
|
||||
$tableName = 'system_admin';
|
||||
$update = [
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
$tableName = 'system_admin';
|
||||
$update = [
|
||||
'username' => $username,
|
||||
'head_img' => '/static/admin/images/head.jpg',
|
||||
'password' => $_password,
|
||||
'password' => $hashedPassword,
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
@@ -88,7 +88,7 @@ CREATE TABLE `ea_system_admin`
|
||||
`auth_ids` varchar(255) DEFAULT NULL COMMENT '角色权限ID',
|
||||
`head_img` varchar(255) DEFAULT NULL COMMENT '头像',
|
||||
`username` varchar(50) NOT NULL DEFAULT '' COMMENT '用户登录名',
|
||||
`password` char(40) NOT NULL DEFAULT '' COMMENT '用户登录密码',
|
||||
`password` varchar(255) NOT NULL DEFAULT '' COMMENT '用户登录密码',
|
||||
`phone` varchar(16) DEFAULT NULL COMMENT '联系手机号',
|
||||
`remark` varchar(255) DEFAULT '' COMMENT '备注说明',
|
||||
`login_num` bigint(20) unsigned DEFAULT '0' COMMENT '登录次数',
|
||||
|
||||
Reference in New Issue
Block a user