当前位置:网站首页>在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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Special characters & escapes in bat
- CDH6 Hue to open a "ASCII" codec can 't encode characters
- 2022还想上岸学习软件测试必看,测试老鸟的肺腑之言...
- 软技能之UML图
- 避免使用 <b>、<i>、<s> 和 <u> 标签
- 检查点是否在矩形内
- Classical Literature Reading--DLO
- [Camp Experience Post] 2022 Cybersecurity Summer Camp
- numpy.isclose
- DRF generating serialization class code
猜你喜欢

技术分享 | 接口测试中如何使用Json 来进行数据交互 ?

@Resource和@Autowired的区别

Docker搭建Mysql主从复制

Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions

经典文献阅读之--DLO

ICLR 2022 Best Paper: Partial Label Learning Based on Contrastive Disambiguation

CDH6的Hue打开出现‘ascii‘ codec can‘t encode characters

Work for 5 years, test case design is bad?To look at the big case design summary

企业防护墙管理,有什么防火墙管理工具?

chrome复制一张图片的base64数据
随机推荐
字节跳动面试官:请你实现一个大文件上传和断点续传
Getting started with IDEA is enough to read this article
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
几道关于golang并发的面试题
访问控制台中的选定节点
Avoid hidden text when loading fonts
npm npm
避免使用 <b>、<i>、<s> 和 <u> 标签
架构基本概念和架构本质
伸展树的特性及实现
Use Jenkins for continuous integration, this knowledge point must be mastered
problem solved
IDEA common plugins
程序员还差对象?new一个就行了
IDEA入门看这一篇就够了
6134. Find the closest node to the given two nodes - force double hundred code
color transparency parameter
FAST-LIO2代码解析(二)
仿牛客网项目第三章:开发社区核心功能(详细步骤和思路)
Several interview questions about golang concurrency