首页 > 代码库 > mysql 中用户默认密码加密问题

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

问题描述:

在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 或者为空

 

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