yii2高级版账号密码问题

2023-06-14,,

yii2高级版默认后台没有密码,生成账号密码步骤:

1、

CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`auth_key` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`password_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password_reset_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`status` smallint(6) NOT NULL DEFAULT '10',
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `password_reset_token` (`password_reset_token`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

2、

在表中添加一个账号

例如:admin

密码生成用common/models/user.php中

setPassword
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
方法的
Yii::$app->security->generatePasswordHash($password);生成密码,然后复制到admin密码项中

yii2高级版账号密码问题的相关教程结束。

《yii2高级版账号密码问题.doc》

下载本文的Word格式文档,以方便收藏与打印。