前言
很久不更新了,想着做一份含金量技术量比较高的文章,做了一份md5解密的网站,使用python语言,主要应用flask库,后期数据库导入应用pymysql
读取文本查py
"""
Author:LuckyRiver
Date:2021
第一个flask项目
"""
from flask import Flask,render_template,request
from md5_decrypt import encrypt_md5
app = Flask(__name__) #创建应用对象
@app.route("/index")
def index():
return render_template("index.html",
title="解密md5")
@app.route("/getmd5",methods=['get'])
def get_md5():
md5_value = request.args.get("md5_value")
status = False
with open("./passwords.txt", "r") as f:
line = f.readline()
while line:
# print(line.strip())
line = f.readline()
if md5_value.lower().strip() == encrypt_md5(line.strip()):
status = True
return line.strip()
# text = "123456"
if status == False:
return "对不起,解不了,请更大的字典"
if __name__ == "__main__":
app.run(debug=True) #
Md5解密库制作
"""
Author:LuckyRiver
Date:2021
md5解密
"""
fromhashlibimportmd5
def encrypt_md5(data):
md=md5()
md.update(data.encode(encoding="utf-8"))
returnmd.hexdigest()
# print(encrypt_md5("123456"))
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
<style>
.a1{
margin:0 auto;
text-align:center;
}
.font{
text-align: center;
}
</style>
<script>
function show_md5() {
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("mydiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "/getmd5?md5_value=" + document.getElementById('md5').value, true);
xmlhttp.send();
document.getElementById('md5').value = "";
}
</script>
</head>
<body style="background-color: pink;">
<h1 style="background-color:red;text-align:center;" id="1">贝塔空间欢迎您</h1>
<hr>
<div class="a1">
<img border="0" src="#" alt="" width="500" height="150" title="这是代码信息">
</div>
<p style="font-family:arial;color:red;font-size:20px;text-align:center;">开始练习</p>
<hr>
<div style="margin-top:70px; font-size:23px; text-align:center;">Welcome <font>Test</font><br>
密文:<input type="text" id="md5"><br>
<input type="button" value = "查询" οnclick="show_md5()">
<div id="mydiv">解密</div>
</div>
</body>
</html>
将文本文件导入到数据库中
"""
Author:LuckyRiver
Date:2021
连接mysql案例
"""
from flask import Flask,render_template,request
from md5_decrypt import encrypt_md5
import pymysql
app = Flask(__name__) #创建应用对象
@app.route("/index")
def index():
return render_template("index.html",
title="解密md5")
@app.route("/getmd5",methods=['get'])
def get_md5():
md5_value = request.args.get("md5_value")
status = False
# with open("dic/passwords", "r") as f:
# line = f.readline()
# while line:
# line = f.readline()
# if md5_value.lower().strip() == encrypt_md5(line.strip()):
# status = True
# return line.strip()
# 打开一个连接
conn = pymysql.connect(host="127.0.0.1", user="root", password="123456", database="mdtest")
# 数据读写
cur = conn.cursor()
# cur.execute("select password from md5")
# results=cur.fetchall()
# for line in results:
# if md5_value.lower().strip() == encrypt_md5(line[0].strip()):
# status = True
# return line[0].strip()
sql = "select * from md5 where md5(password) = '"+md5_value+"'"
cur.execute(sql)
# 关闭连接
result = cur.fetchone()
if result:
status = True
return result[1]
cur.close()
conn.close()
if status == False:
return "对不起,解不了,请更换更大的字典"
if __name__ == "__main__":
app.run(debug=True) #
快速算法读取查库
"""
Author:LuckyRiver
Date:2021
第一个flask项目
"""
from flask import Flask,render_template,request
from md5_decrypt import encrypt_md5
import pymysql
app = Flask(__name__) #创建应用对象
@app.route("/index")
def index():
return render_template("index.html",
title="解密md5")
@app.route("/getmd5",methods=['get'])
def get_md5():
md5_value = request.args.get("md5_value")
status = False
# 打开一个连接
conn = pymysql.connect(host="127.0.0.1", user="root", password="123456", database="mdtest")
# 数据读写
cur = conn.cursor()
# cur.execute("select password from md5")
# results=cur.fetchall()
# for line in results:
# if md5_value.lower().strip() == encrypt_md5(line[0].strip()):
# status = True
# return line[0].strip()
sql = "select * from md5 where md5(password) = '"+md5_value+"'"
cur.execute(sql)
# 关闭连接
result = cur.fetchone()
if result:
status = True
return result[1]
cur.close()
conn.close()
if status == False:
return "对不起,解不了,请更换更大的字典"
if __name__ == "__main__":
app.run(debug=True) #
总结
md5_decrypt库是自我制作的,第二段代码制作好即可调用,对库使用函数方法清晰认知,自我调出,再使用较为庞大的密码库文件,MD5加密解密使用即可轻松完成。