当前位置:网站首页>在MySQL中使用MD5加密【入门体验】
在MySQL中使用MD5加密【入门体验】
2022-08-01 23:44:00 【bhegi_seg】
什么是MD5?
MD5信息摘要算法(英语:MD5 Message-Digest Agorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值(hash value),用于确保信息传输完整一致。MD5由美国密码学家罗纳德·李维斯特(Ronald LinnRivest))设计,于1992年公开,用以取代MD4算法。这套算法的程序在RFC1321标准中被加以规范。1996年后该算法被证实存在弱点,可以被加以破解,对于需要高度安全性的数据,专家一般建议改用其他算法,如SHA-2。2004年,证实MD5算法无法防止碰撞(collision),因此不适用于安全性认证,如SSL公开密钥认证或是数字签名等用途。【以上概念引自百度百科】
MD5初体验

在mysql中准备一个简单的用户表用于案例操作。
接下来测试各种sql语句:
普通插入语句(密码明文):
-- 普通新增语句(明文密码)
insert into user(uname,upass) values ('tom','1001');
在插入信息时加密**:**
-- 插入时使用MD5 算法加密
insert into user(uname,upass) values ('jack',MD5('1002'));
查询查看结果:

修改: 使用MD5算法将账号admin的密码修改。
-- 将原密码换为MD5加密后的密码
update user set upass=MD5(upass) where id =1;
-- 将原密码123456修改为 MD5加密后的密码(666)
update user set upass=MD5('666') where id =2;
结果:

加密全部密码:
-- 加密全部密码
update user set upass=MD5(upass)

条件查询,进行验证:
-- 根据账号密码 查询对应账号信息
select * from user where uname='admin' and upass=MD5('123')

-- 测试 将密码修改为666 的账号信息
select * from user where uname='root' and upass=MD5('666')

以上是通过MD5算法在mysql数据库中对一些信息的简单加密,具体知识有待整理。
MySQL中其他方式
(1) PASSWORD()函数:
-- password() 函数加密
update userinfo set password =password('333') where id=6
-- 查询验证
select * from userinfo where password=password('333')
password(str)从原明文密码str计算并返回加密后的密码字符串,当参数为null时,返回null。password加密是单向的,不可逆。
(2) ENCODE()函数
ENCODE(str,pass_str)函数用于对纯文本字符串进行编码,在编码后返回二进制字符串.
使用pswd_str作为密码,加密str.
str:它用于指定要编码的纯文本
pass_str:用于指定密码字符串以对纯文本字符串进行编码.
-- 字符串
select encode('hello','nice')

-- 字符串和数字
select encode('nihao666','nice')

(3) DECODE(crypt_str,pass_str)
使用pswd_str作为密码,解密加密字符串crypt_str,crypt_str是由encode()返回的字符串。
select DECODE('nihao666','nice')

-- 使用decode函数解密encode加密的字符串
select DECODE(ENCODE('nihao666','nice'),'nice');

【未完待续…】
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- [Camp Experience Post] 2022 Cybersecurity Summer Camp
- 递归:方法调用自身
- Appears in oozie on CDH's hue, error submitting Coordinator My Schedule
- 2022还想上岸学习软件测试必看,测试老鸟的肺腑之言...
- Various Joins of Sql
- 获取小猪民宿(短租)数据
- JAX-based activation function, softmax function and cross entropy function
- Spark Sql之join on and和where
- IDEA common plugins
- The third chapter of the imitation cattle network project: develop the core functions of the community (detailed steps and ideas)
猜你喜欢
随机推荐
解决端口占用
问题解决方式了
Loading configuration of Nacos configuration center
Is TCP reliable?Why?
计算两点之间的中点
论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
nodejs--process
qt-faststart 安装使用
字节跳动面试官:请你实现一个大文件上传和断点续传
JAX-based activation function, softmax function and cross entropy function
【C语言进阶】文件操作(二)
一道golang中关于iota的面试题
cmd指令
分享一份接口测试项目(非常值得练手)
斜堆、、、
6132. 使数组中所有元素都等于零-快速排序法
With a monthly salary of 12K, the butterfly changed to a new one and moved forward bravely - she doubled her monthly salary through the career change test~
IDEA常用插件
drf生成序列化类代码
The monthly salary of the test post is 5-9k, how to increase the salary to 25k?









