吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2233|回复: 4
收起左侧

[Python 转载] PyQt5初步(2)——本地登录页面

[复制链接]
麦田孤望者 发表于 2020-2-22 17:43
成品及源码:链接:https://pan.baidu.com/s/1aQdD7xxtoqp1WAmWXlnZPA 提取码:4t9z



源码:
main.py内容
[Python] 纯文本查看 复制代码
import sys,os,json,re
from PyQt5.QtWidgets import QApplication, QMainWindow
from functools import partial
import hashlib
import login

path = os.path.dirname(os.path.realpath(__file__))+'\\'
try:
with open(path+'users.txt','r') as f:
pass
except:
with open(path+'users.txt','w') as f:
f.write('91 93')
def en_decode(txt,mode):
wi1 = "'[,0] \""
wi2 = 'OCP0L%@'
if mode == 'en':
return txt.translate(str.maketrans(wi1,wi2))
else:
return txt.translate(str.maketrans(wi2,wi1))

def acsii(txt,mode):
if mode=='en':
return ' '.join([str(ord(i)) for i in txt])
else:
a=''
txt = re.sub('\\n',' ',txt)
txt = txt.split(' ')
#print(txt)
for i in txt:
a+=chr(int(i))
return a

def sign_in(ui):
user = str(ui.lineEdit_user.text())
psw = str(ui.lineEdit_psw.text())
if len(psw) < 6:
ui.textBrowser.setText('密码至少6位!')
return False

h1 = hashlib.md5()
h1.update(user.encode(encoding='utf-8'))#
h2 = hashlib.md5()
h2.update(psw.encode(encoding='utf-8'))#.hexdigest()

with open(path+'users.txt','r') as f:
users = str(f.read())
##print(users)

users = acsii(users,'de')
#print(users)

users = en_decode(users,'de')
#print(users)

user_json = json.loads(users.replace('\'','"'))
#print(type(user_json),user_json)
user_json.append(["{}".format(h1.hexdigest()),"{}".format(h2.hexdigest())])
#print(user_json)
list1 = []
for i in user_json:
if i not in list1:
list1.append(i)
user_json=list1

user_json = acsii(str(user_json),'en')
#user_json = [ord(i) for i in str(user_json)]
#user_json = ' '.join(user_json)
#print(user_json)



with open(path+'users.txt','w') as f:
f.write(user_json)
#print(user_json)
ui.textBrowser.setText('注册成功!您的信息为\n账号:{}\n密码:{}'.format(user,psw))
ui.lineEdit_user.setText('')
ui.lineEdit_psw.setText('')



def check(ui):
user = str(ui.lineEdit_user.text())
psw = str(ui.lineEdit_psw.text())

h1 = hashlib.md5()
h1.update(user.encode(encoding='utf-8'))#
h2 = hashlib.md5()
h2.update(psw.encode(encoding='utf-8'))

with open(path+'users.txt','r') as f:
users = str(f.read())
#print(users)
users = acsii(users,'de')
users = en_decode(users,'de')
user_json = json.loads(users.replace('\'','"'))

in_result = [h1.hexdigest(),h2.hexdigest()]
#print(in_result)

if in_result in user_json:
#print('Success!')
ui.textBrowser.setText(user+',欢迎回来!')
ui.lineEdit_user.setText('')
ui.lineEdit_psw.setText('')
else:
ui.textBrowser.setText('Failed!')

if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = login.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
MainWindow.setFixedSize(MainWindow.width(), MainWindow.height())
ui.LoginButton.clicked.connect(partial(check, ui))
ui.SignInButton.clicked.connect(partial(sign_in, ui))

sys.exit(app.exec_())


login.py文件内容
[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(359, 127)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.lineEdit_user = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_user.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.lineEdit_user.setObjectName("lineEdit_user")
self.gridLayout.addWidget(self.lineEdit_user, 0, 1, 1, 1)
self.label_psw = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(14)
self.label_psw.setFont(font)
self.label_psw.setObjectName("label_psw")
self.gridLayout.addWidget(self.label_psw, 1, 0, 1, 1)
self.lineEdit_psw = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_psw.setObjectName("lineEdit_psw")
self.gridLayout.addWidget(self.lineEdit_psw, 1, 1, 1, 1)
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setObjectName("textBrowser")
self.gridLayout.addWidget(self.textBrowser, 0, 2, 3, 1)
self.label_user = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(14)
self.label_user.setFont(font)
self.label_user.setObjectName("label_user")
self.gridLayout.addWidget(self.label_user, 0, 0, 1, 1)
self.LoginButton = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(13)
self.LoginButton.setFont(font)
self.LoginButton.setObjectName("LoginButton")
self.gridLayout.addWidget(self.LoginButton, 2, 0, 1, 1)
self.SignInButton = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
self.SignInButton.setFont(font)
self.SignInButton.setObjectName("SignInButton")
self.gridLayout.addWidget(self.SignInButton, 2, 1, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Login"))
self.label_psw.setText(_translate("MainWindow", "密码"))
self.label_user.setText(_translate("MainWindow", "用户名"))
self.LoginButton.setText(_translate("MainWindow", "登录"))
self.SignInButton.setText(_translate("MainWindow", "注册"))

免费评分

参与人数 1吾爱币 +1 收起 理由
haol666 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 麦田孤望者 发表于 2020-2-22 17:47
诶我不知道为什么我缩进没了...看网盘文件吧
hxm5201314 发表于 2020-2-22 18:07
haol666 发表于 2020-2-22 18:48
dyliuyunfei 发表于 2020-2-23 11:53
hxm5201314 发表于 2020-2-22 18:07
楼主想问下PYQT打包exe是不是很麻烦?

不是麻烦,是文件有点大~ 很小的一个功能程序弄下来30M左右
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-16 23:29

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表