您的位置:首页 > 数据库 > MySQL

mysql 中用户默认密码加密问题

2017-06-08 11:33 399 查看
问题描述:

在mysql中 user表中新增用户默认密码为123456,但是在数据库中显示不能为明文,而mysql的默认字段不能用函数

解决方法:

用触发器

delimiter |
drop trigger if exists default_user_pwd;
create trigger default_user_pwd before insert on user
for each row
if (new.pwd is null or new.pwd ='' or new.pwd ='123456' )then
set new.pwd = ENCODE('123456','password');
end if;|

使用范围

可以检测某些值是否null 或者为空

补充:

由于encode 和decode 在使用中会生成空白字符串的问题

改用base64

delimiter |
drop trigger if exists default_user_pwd;
create trigger default_user_pwd before insert on user
for each row
if (new.pwd is null or new.pwd ='' or new.pwd ='123456' )then

set new.Pwd = to_base64('123456');
end if;|
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: