Compare commits

..

2 Commits

Author SHA1 Message Date
Lmath d2e5f7389b 使用 password_hash 存储密码哈希 2020-06-14 09:07:58 +08:00
Lmath ba8d777313 使用 utf8mb4 代替 utf8 2020-06-14 08:49:29 +08:00
7 changed files with 51 additions and 52 deletions

18
.env
View File

@ -1 +1,17 @@
APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8mb4
DEBUG = true
[LANG]
default_lang = zh-cn

View File

@ -32,13 +32,6 @@ function vae_input($name='')
return $param;
}
//随机字符串默认长度10
function vae_set_salt($num = 10){
$str = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890';
$salt = substr(str_shuffle($str), 10, $num);
return $salt;
}
//递归排序
function vae_set_recursion($result,$pid=0,$format="L "){
/*记录排序后的类别数组*/
@ -82,9 +75,4 @@ function vae_list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'children',
}
}
return $tree;
}
//vaeThink加密方式
function vae_set_password($pwd, $salt){
return md5(md5($pwd.$salt).$salt);
}

View File

@ -65,8 +65,7 @@ class Admin extends BaseController
'group_id' => 'require',
]);
$param['salt'] = vae_set_salt(20);
$param['pwd'] = vae_set_password($param['password'],$param['salt']);
$param['pwd'] = password_hash($param['password'], PASSWORD_DEFAULT);
$param['groups'] = implode(',',$param['group_id']);
$param['create_time'] = time();
@ -114,11 +113,9 @@ class Admin extends BaseController
if(empty($param['password_confirm']) or $param['password_confirm'] !== $param['password']) {
return vae_assign(202,'两次密码不一致');
}
$param['salt'] = vae_set_salt(20);
$param['pwd'] = vae_set_password($param['password'],$param['salt']);
$param['pwd'] = password_hash($param['password'],PASSWORD_DEFAULT);
} else {
unset($param['pwd']);
unset($param['salt']);
}
$param['groups'] = implode(',',$param['group_id']);
$param['update_time'] = time();

View File

@ -226,13 +226,11 @@ class Index extends BaseController
if(empty($param['password_confirm']) or $param['password_confirm'] !== $param['password']) {
return vae_assign(202,'两次密码不一致');
}
$param['salt'] = vae_set_salt(20);
$param['pwd'] = vae_set_password($param['password'],$param['salt']);
$param['pwd'] = password_hash($param['password'],PASSWORD_DEFAULT);
}
else
{
unset($param['pwd']);
unset($param['salt']);
}
$param['update_time'] = time();

View File

@ -42,10 +42,12 @@ class Publicer extends BaseController
if(empty($admin)) {
return vae_assign(202,'用户名或密码错误');
}
$param['pwd'] = vae_set_password($param['password'],$admin['salt']);
if($admin['pwd'] !== $param['pwd']) {
if(!password_verify($param['password'],$admin['pwd'])) {
return vae_assign(202,'用户名或密码错误');
}
if(password_needs_rehash($admin['pwd'],PASSWORD_DEFAULT)) {
Db::name('admin')->where(['id'=>$admin['id']])->update(['pwd'=>password_hash($param['password'],PASSWORD_DEFAULT)]);
}
if($admin['status'] == 0){
return vae_assign(202,'该用户禁止登陆,请于系统所有者联系');
}

View File

@ -83,13 +83,13 @@ class Install extends BaseController
return json(['code'=>0,'msg'=>'数据库链接失败:'.$error]);die;
}
// 设置字符集
$link->query("SET NAMES 'utf8'");
$link->query("SET NAMES 'utf8mb4'");
if($link->server_info < 5.0){
return json(['code'=>0,'msg'=>'请将您的mysql升级到5.0以上']);die;
}
// 创建数据库并选中
if(!$link->select_db($data['DB_NAME'])){
$create_sql='CREATE DATABASE IF NOT EXISTS '.$data['DB_NAME'].' DEFAULT CHARACTER SET utf8;';
$create_sql='CREATE DATABASE IF NOT EXISTS '.$data['DB_NAME'].' DEFAULT CHARACTER SET utf8mb4;';
if(!$link->query($create_sql)){
return json(['code'=>0,'msg'=>'数据库连接失败']);die;
}
@ -109,15 +109,14 @@ class Install extends BaseController
$password = $data['password'];
$nickname = 'Admin';
$thumb = '/static/admin_static/images/vae.jpg';
$salt = substr(str_shuffle('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890'), 10, 20);
$password = md5(md5($password.$salt).$salt);
$password = password_hash($password,PASSWORD_DEFAULT);
$create_time = time();
$update_time = time();
$caeate_admin_sql = "INSERT INTO ".$data['DB_PREFIX']."admin ".
"(username,pwd, nickname,thumb,salt,create_time,update_time) "
"(username,pwd, nickname,thumb,create_time,update_time) "
."VALUES "
."('$username','$password','$nickname','$thumb','$salt','$create_time','$update_time')";
."('$username','$password','$nickname','$thumb','$create_time','$update_time')";
if(!$link->query($caeate_admin_sql)) {
return json(['code'=>0,'msg'=>'创建管理员信息失败']);
}

View File

@ -23,7 +23,6 @@ CREATE TABLE `vae_admin` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL DEFAULT '',
`pwd` varchar(255) NOT NULL DEFAULT '',
`salt` varchar(50) NOT NULL DEFAULT '',
`status` int(1) NOT NULL DEFAULT '1' COMMENT '1正常-1禁止登陆',
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
@ -35,7 +34,7 @@ CREATE TABLE `vae_admin` (
`groups` varchar(255) NOT NULL DEFAULT '' COMMENT '权限组,隔开',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`id`,`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='管理员';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管理员';
-- ----------------------------
-- Records of vae_admin
@ -49,13 +48,13 @@ CREATE TABLE `vae_admin_group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL DEFAULT '',
`status` int(1) NOT NULL DEFAULT '1',
`rules` text CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '用户组拥有的规则id 多个规则","隔开',
`rules` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '用户组拥有的规则id 多个规则","隔开',
`desc` text COMMENT '备注',
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限分组';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限分组';
-- ----------------------------
-- Records of vae_admin_group
@ -68,7 +67,7 @@ DROP TABLE IF EXISTS `vae_admin_rule`;
CREATE TABLE `vae_admin_rule` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(11) unsigned NOT NULL DEFAULT '0',
`src` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '规则',
`src` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '规则',
`title` varchar(255) NOT NULL DEFAULT '',
`is_menu` int(1) NOT NULL DEFAULT '1' COMMENT '1是菜单2不是',
`font_family` varchar(50) DEFAULT '' COMMENT '图标来源',
@ -78,7 +77,7 @@ CREATE TABLE `vae_admin_rule` (
`update_time` int(11) NOT NULL COMMENT '0',
PRIMARY KEY (`id`),
KEY `name` (`src`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8 COMMENT='权限节点';
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8mb4 COMMENT='权限节点';
-- ----------------------------
-- Records of vae_admin_rule
@ -143,7 +142,7 @@ DROP TABLE IF EXISTS `vae_cate`;
CREATE TABLE `vae_cate` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`icon` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`icon` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`pid` int(11) NOT NULL DEFAULT '0',
`status` int(1) NOT NULL DEFAULT '1' COMMENT '1正常0下架',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序,值越大越靠前',
@ -151,7 +150,7 @@ CREATE TABLE `vae_cate` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='分类';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分类';
-- ----------------------------
-- Records of vae_cate
@ -163,11 +162,11 @@ CREATE TABLE `vae_cate` (
DROP TABLE IF EXISTS `vae_cate_group`;
CREATE TABLE `vae_cate_group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`key` varchar(50) NOT NULL,
`desc` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='分类分组';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='分类分组';
-- ----------------------------
-- Records of vae_cate_group
@ -179,9 +178,9 @@ CREATE TABLE `vae_cate_group` (
DROP TABLE IF EXISTS `vae_content`;
CREATE TABLE `vae_content` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`img` text CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '图片,多图用,隔开',
`img` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '图片,多图用,隔开',
`status` int(1) NOT NULL DEFAULT '1' COMMENT '1正常0下架',
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`desc` varchar(500) DEFAULT NULL COMMENT '概要',
`content` text COMMENT '详情',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序,值越大越靠前',
@ -190,7 +189,7 @@ CREATE TABLE `vae_content` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='内容';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='内容';
-- ----------------------------
-- Records of vae_content
@ -202,12 +201,12 @@ CREATE TABLE `vae_content` (
DROP TABLE IF EXISTS `vae_content_group`;
CREATE TABLE `vae_content_group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`key` varchar(50) NOT NULL,
`cate_group_id` int(11) NOT NULL DEFAULT '0' COMMENT '分类组id',
`desc` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='内容分组';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='内容分组';
-- ----------------------------
-- Records of vae_content_group
@ -221,14 +220,14 @@ CREATE TABLE `vae_nav` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`icon` varchar(255) NOT NULL,
`src` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`src` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`status` int(1) NOT NULL DEFAULT '1' COMMENT '1正常0下架',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序,值越大越靠前',
`nav_group_id` int(11) NOT NULL DEFAULT '0',
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='导航';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='导航';
-- ----------------------------
-- Records of vae_nav
@ -240,11 +239,11 @@ CREATE TABLE `vae_nav` (
DROP TABLE IF EXISTS `vae_nav_group`;
CREATE TABLE `vae_nav_group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`key` varchar(50) NOT NULL,
`desc` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='导航分组';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='导航分组';
-- ----------------------------
-- Records of vae_nav_group
@ -263,7 +262,7 @@ CREATE TABLE `vae_route` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='路由设置';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='路由设置';
-- ----------------------------
-- Records of vae_route
@ -283,7 +282,7 @@ CREATE TABLE `vae_slide` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='轮播';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='轮播';
-- ----------------------------
-- Records of vae_slide
@ -295,11 +294,11 @@ CREATE TABLE `vae_slide` (
DROP TABLE IF EXISTS `vae_slide_group`;
CREATE TABLE `vae_slide_group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`key` varchar(50) NOT NULL,
`desc` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='轮播分组';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='轮播分组';
-- ----------------------------
-- Records of vae_slide_group