#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC
@license: None
@contact: JHC000abc@gmail.com
@file: make_secret.py
@time: 2022/06/23/ 13:28
@desc:密码生成
'''
import datetime
import json
import random
import hashlib
import re
import numpy as np
from connect_redis import Redis
def gen_md5_id(item):
md5_machine = hashlib.md5()
md5_machine.update(item.encode('utf-8'))
return md5_machine.hexdigest()
def make_secret(secret_key,remarks):
res = []
char = {"@": "a", "-": "b", "_": "c", "X": "d",
"Y": "e", "*": "f", "Z": "g", "H": "h",
"J": "i", ".": "j"," ": "k", "M": "m",
"N": "n"}
time = str(datetime.datetime.now()).replace(".", "")
random_num = str(random.randint(1, 1111))
secret_key = secret_key
opt = np.random.randint(1, 3, 3)
res.insert(opt[0], time)
res.insert(opt[1], random_num)
res.insert(opt[2], secret_key)
second_secret = gen_md5_id("".join(res))
for i in second_secret:
random_replace = random.randint(0, 10)
random_count = random.randint(0, 32)
second_secret = re.sub(list(char.values())[random_replace],
list(char.keys())[random_replace],
second_secret,
count=random_count)
second_secret = second_secret[2:13]
remarks = gen_md5_id(remarks)
Redis.write_one_hash(key=secret_key, field=remarks, value=second_secret)
return second_secret
# if __name__ == '__main__':
# secret_key = input("请输入要生成的密文名称:")
# remarks = input("请输入备注信息:")
# res = make_secret(secret_key,remarks)
# print("密文为:{}".format(res))
#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC
@license: None
@contact: JHC000abc@gmail.com
@file: make_secret_control_win.py
@time: 2022/06/23/ 13:54
@desc:界面逻辑
'''
import threading
import pyperclip
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPalette, QPixmap, QBrush, QPaintEvent
from PyQt5.QtCore import Qt,pyqtSignal
from threading import Thread
import make_secret_ui
import make_secret
class Make_Secret(QWidget):
show_secret = pyqtSignal(str)
def __init__(self):
QWidget.__init__(self)
self.ui = make_secret_ui.Ui_Form()
self.ui.setupUi(self)
self.setAutoFillBackground(True)
self.setWindowFlags(Qt.FramelessWindowHint)
self.ui.secret_label.setDisabled(True)
self.ui.secret_label.setStyleSheet(
"color: rgb(255, 255, 255);"
)
bg_path = R"./res/bg.png"
self.pix = QPixmap(bg_path)
self.pix = self.pix.scaled(self.width(), self.height())
self.palette = QPalette()
self.palette.setBrush(QPalette.Background, QBrush(self.pix))
self.setPalette(self.palette)
self.setWindowFlags(Qt.FramelessWindowHint)
self.ui.secret_name_lineEdit.setPlaceholderText("请输入密文名称")
self.ui.remark_lineEdit.setPlaceholderText("请输入备注信息")
self.ui.fork_btn.clicked.connect(self.slot_fork)
self.ui.make_secret_btn.clicked.connect(self.slot_make_secret_btn)
self.show_secret.connect(self.slot_show_secret)
self.ui.secret_label.clicked.connect(self.slot_copy_secret)
def slot_show_secret(self,secret):
if secret != "0":
self.ui.secret_label.setText("密钥为:{}".format(secret))
self.ui.secret_label.setDisabled(False)
self.ui.secret_label.setStyleSheet(
"color: rgb(255, 0, 0);"
)
else:
self.ui.secret_label.setText(" 密文/备注不能为空 ")
self.recover_status()
def slot_copy_secret(self):
secret = self.ui.secret_label.text()
print("secret",secret)
if secret != " 密文/备注不能为空 " and secret != " 点击拷贝密文 ":
pyperclip.copy(secret.split(":")[1])
def recover_status(self):
self.ui.make_secret_btn.setDisabled(False)
self.ui.secret_name_lineEdit.clear()
self.ui.remark_lineEdit.clear()
def slot_fork(self):
self.close()
def slot_make_secret_btn(self):
self.ui.make_secret_btn.setDisabled(True)
secret_name = self.ui.secret_name_lineEdit.text()
remark = self.ui.remark_lineEdit.text()
if secret_name == "" or remark == "":
self.show_secret.emit("0")
else:
threading.Thread(target=self.get_secret,args=(secret_name, remark,)).start()
def get_secret(self,secret_name,remark):
secret = make_secret.make_secret(secret_name, remark)
self.show_secret.emit(secret)
# def paintEvent(self, a0: QPaintEvent) -> None:
# self.pix = self.pix.scaled(self.width(), self.height())
# self.palette = QPalette()
# self.palette.setBrush(QPalette.Background, QBrush(self.pix))
# self.setPalette(self.palette)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
myForm = Make_Secret()
with open(R'res/style.qss', 'r') as f:
app.setStyleSheet(f.read())
myForm.show()
sys.exit(app.exec())
UI
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'make_secret_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import border
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(311, 224)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
Form.setSizePolicy(sizePolicy)
self.gridLayout = QtWidgets.QGridLayout(Form)
self.gridLayout.setObjectName("gridLayout")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.fork_btn = QtWidgets.QPushButton(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.fork_btn.sizePolicy().hasHeightForWidth())
self.fork_btn.setSizePolicy(sizePolicy)
self.fork_btn.setStyleSheet("border-image: url(:/url/res/fork.png);")
self.fork_btn.setText("")
self.fork_btn.setObjectName("fork_btn")
self.horizontalLayout.addWidget(self.fork_btn)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.horizontalLayout.setStretch(0, 100)
self.horizontalLayout.setStretch(1, 1)
self.horizontalLayout.setStretch(2, 1)
self.verticalLayout.addLayout(self.horizontalLayout)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem2)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem3)
self.tips_label = QtWidgets.QLabel(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tips_label.sizePolicy().hasHeightForWidth())
self.tips_label.setSizePolicy(sizePolicy)
self.tips_label.setObjectName("tips_label")
self.horizontalLayout_2.addWidget(self.tips_label, 0, QtCore.Qt.AlignHCenter)
spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem4)
self.verticalLayout.addLayout(self.horizontalLayout_2)
spacerItem5 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem5)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem6)
self.secret_name_lineEdit = QtWidgets.QLineEdit(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.secret_name_lineEdit.sizePolicy().hasHeightForWidth())
self.secret_name_lineEdit.setSizePolicy(sizePolicy)
self.secret_name_lineEdit.setObjectName("secret_name_lineEdit")
self.horizontalLayout_4.addWidget(self.secret_name_lineEdit)
spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem7)
self.verticalLayout.addLayout(self.horizontalLayout_4)
spacerItem8 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem8)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem9 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem9)
self.remark_lineEdit = QtWidgets.QLineEdit(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.remark_lineEdit.sizePolicy().hasHeightForWidth())
self.remark_lineEdit.setSizePolicy(sizePolicy)
self.remark_lineEdit.setObjectName("remark_lineEdit")
self.horizontalLayout_3.addWidget(self.remark_lineEdit)
spacerItem10 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem10)
self.verticalLayout.addLayout(self.horizontalLayout_3)
spacerItem11 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem11)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
spacerItem12 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem12)
self.make_secret_btn = QtWidgets.QPushButton(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.make_secret_btn.sizePolicy().hasHeightForWidth())
self.make_secret_btn.setSizePolicy(sizePolicy)
self.make_secret_btn.setObjectName("make_secret_btn")
self.horizontalLayout_5.addWidget(self.make_secret_btn)
spacerItem13 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem13)
self.horizontalLayout_5.setStretch(0, 5)
self.horizontalLayout_5.setStretch(1, 2)
self.horizontalLayout_5.setStretch(2, 5)
self.verticalLayout.addLayout(self.horizontalLayout_5)
spacerItem14 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem14)
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
spacerItem15 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem15)
self.secret_label = QtWidgets.QPushButton(Form)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.secret_label.sizePolicy().hasHeightForWidth())
self.secret_label.setSizePolicy(sizePolicy)
self.secret_label.setObjectName("secret_label")
self.horizontalLayout_6.addWidget(self.secret_label)
spacerItem16 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem16)
self.verticalLayout.addLayout(self.horizontalLayout_6)
spacerItem17 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem17)
self.verticalLayout.setStretch(0, 5)
self.verticalLayout.setStretch(1, 1)
self.verticalLayout.setStretch(2, 30)
self.verticalLayout.setStretch(3, 1)
self.verticalLayout.setStretch(4, 2)
self.verticalLayout.setStretch(5, 1)
self.verticalLayout.setStretch(6, 2)
self.verticalLayout.setStretch(7, 1)
self.verticalLayout.setStretch(8, 2)
self.verticalLayout.setStretch(9, 1)
self.verticalLayout.setStretch(10, 2)
self.verticalLayout.setStretch(11, 20)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.tips_label.setText(_translate("Form", "密钥生成器"))
self.make_secret_btn.setText(_translate("Form", "生成密钥"))
self.secret_label.setText(_translate("Form", " 点击拷贝密文 "))
# import border_rc
Redis存储
#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC
@license: None
@contact: JHC000abc@gmail.com
@file: connect_redis.py
@time: 2022/06/23/ 09:51
@desc:
'''
import redis
class Redis():
@staticmethod
def get_r():
r = redis.Redis(host="localhost", port="6379",db=1)
return r
@classmethod
def view_all_keys(cls):
r = cls.get_r()
return r.keys()
@classmethod
def write_one_hash(cls, key, field,value):
r = cls.get_r()
return r.hset(key, field,value)
@classmethod
def write_many_hash(cls, key, **kwargs):
r = cls.get_r()
return r.hmset(key, kwargs)
@classmethod
def get_on_hash(cls,key,field):
r = cls.get_r()
return r.hget(key,field)
@classmethod
def get_many_hash(cls, key, *args):
r = cls.get_r()
return r.hmget(key, *args)
@classmethod
def get_len_hash(cls,key):
r = cls.get_r()
return r.hlen(key)
@classmethod
def check_exists(cls,key,field):
'''
return 1 or 0
'''
r = cls.get_r()
return r.exists(key,field)
@classmethod
def setnx(cls,key,field,value):
'''
return 1 or 0
'''
r = cls.get_r()
return r.hsetnx(key,field,value)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/156918.html