当前位置:网站首页>在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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Secondary Vocational Network Security Competition B7 Competition Deployment Process
- The Spark of Sql join on the and and where
- @Scheduled注解详解
- 2022 6th Strong Net Cup Part WP
- cdh6 opens oozieWeb page, Oozie web console is disabled.
- 避免使用 <b>、<i>、<s> 和 <u> 标签
- chrome copies the base64 data of an image
- ICLR 2022 Best Paper: Partial Label Learning Based on Contrastive Disambiguation
- 一款简洁的文件传输工具
- numpy.unique
猜你喜欢

伸展树的特性及实现

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~

Appears in oozie on CDH's hue, error submitting Coordinator My Schedule

TCP 可靠吗?为什么?

请问什么是 CICD

云原生DevOps环境搭建

Building a cloud-native DevOps environment

Docker搭建Mysql主从复制

【C语言进阶】文件操作(二)

一款简洁的文件传输工具
随机推荐
ELK日志采集
Several interview questions about golang concurrency
@Resource和@Autowired的区别
2022第六届强网杯部分wp
Quartus 使用 tcl 文件快速配置管脚
npm npm
几道关于golang并发的面试题
加载字体时避免隐藏文本
中职网络安全竞赛B7比赛部署流程
Docker搭建Mysql主从复制
UI自动化测试框架搭建-标记性能较差用例
颜色透明参数
请问什么是 CICD
邻接表与邻接矩阵
使用Jenkins做持续集成,这个知识点必须要掌握
Always use "noopener" or "noreferrer" for links that open in a new tab
Is TCP reliable?Why?
The Spark of Sql join on the and and where
numpy.hstack
YOLO等目标检测模型的非极大值抑制NMS和评价指标(Acc, Precision, Recall, AP, mAP, RoI)、YOLOv5中[email protected]与