Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EMUAFactory
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mayinghao
EMUAFactory
Commits
a7025954
Commit
a7025954
authored
Jun 24, 2025
by
mayinghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加记住密码记住用户名按钮及其功能
parent
278ed5cb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
6 deletions
+148
-6
login.py
login.py
+8
-0
login.ui
login.ui
+31
-4
main.py
main.py
+109
-2
config.cpython-38.pyc
multipleThread/__pycache__/config.cpython-38.pyc
+0
-0
thread_resume.cpython-38.pyc
multipleThread/__pycache__/thread_resume.cpython-38.pyc
+0
-0
thread_upload.cpython-38.pyc
multipleThread/__pycache__/thread_upload.cpython-38.pyc
+0
-0
No files found.
login.py
View file @
a7025954
...
@@ -237,6 +237,12 @@ class Ui_LoginWindow(object):
...
@@ -237,6 +237,12 @@ class Ui_LoginWindow(object):
self
.
stackedWidget
.
addWidget
(
self
.
page_2
)
self
.
stackedWidget
.
addWidget
(
self
.
page_2
)
self
.
page_3
=
QtWidgets
.
QWidget
()
self
.
page_3
=
QtWidgets
.
QWidget
()
self
.
page_3
.
setObjectName
(
"page_3"
)
self
.
page_3
.
setObjectName
(
"page_3"
)
self
.
checkBox
=
QtWidgets
.
QCheckBox
(
self
.
page_3
)
self
.
checkBox
.
setGeometry
(
QtCore
.
QRect
(
30
,
10
,
71
,
16
))
self
.
checkBox
.
setObjectName
(
"checkBox"
)
self
.
checkBox_2
=
QtWidgets
.
QCheckBox
(
self
.
page_3
)
self
.
checkBox_2
.
setGeometry
(
QtCore
.
QRect
(
140
,
10
,
71
,
16
))
self
.
checkBox_2
.
setObjectName
(
"checkBox_2"
)
self
.
stackedWidget
.
addWidget
(
self
.
page_3
)
self
.
stackedWidget
.
addWidget
(
self
.
page_3
)
self
.
page_4
=
QtWidgets
.
QWidget
()
self
.
page_4
=
QtWidgets
.
QWidget
()
self
.
page_4
.
setObjectName
(
"page_4"
)
self
.
page_4
.
setObjectName
(
"page_4"
)
...
@@ -287,6 +293,8 @@ class Ui_LoginWindow(object):
...
@@ -287,6 +293,8 @@ class Ui_LoginWindow(object):
self
.
label_3
.
setText
(
_translate
(
"LoginWindow"
,
"密码错误或者账户不存在"
))
self
.
label_3
.
setText
(
_translate
(
"LoginWindow"
,
"密码错误或者账户不存在"
))
self
.
label_5
.
setText
(
_translate
(
"LoginWindow"
,
"用户名或者密码不能为空"
))
self
.
label_5
.
setText
(
_translate
(
"LoginWindow"
,
"用户名或者密码不能为空"
))
self
.
label_6
.
setText
(
_translate
(
"LoginWindow"
,
"密码不一致"
))
self
.
label_6
.
setText
(
_translate
(
"LoginWindow"
,
"密码不一致"
))
self
.
checkBox
.
setText
(
_translate
(
"LoginWindow"
,
"记住账号"
))
self
.
checkBox_2
.
setText
(
_translate
(
"LoginWindow"
,
"记住密码"
))
self
.
label_7
.
setText
(
_translate
(
"LoginWindow"
,
"用户名已经存在"
))
self
.
label_7
.
setText
(
_translate
(
"LoginWindow"
,
"用户名已经存在"
))
self
.
label_4
.
setText
(
_translate
(
"LoginWindow"
,
"密码和用户名不能为空"
))
self
.
label_4
.
setText
(
_translate
(
"LoginWindow"
,
"密码和用户名不能为空"
))
import
res_rc
import
res_rc
login.ui
View file @
a7025954
...
@@ -112,7 +112,7 @@ padding-bottom:5px;
...
@@ -112,7 +112,7 @@ padding-bottom:5px;
<string/>
<string/>
</property>
</property>
<property
name=
"icon"
>
<property
name=
"icon"
>
<iconset
resource=
"res.qrc"
>
<iconset>
<normaloff>
:/icons/icons/close.svg
</normaloff>
:/icons/icons/close.svg
</iconset>
<normaloff>
:/icons/icons/close.svg
</normaloff>
:/icons/icons/close.svg
</iconset>
</property>
</property>
</widget>
</widget>
...
@@ -414,7 +414,7 @@ padding-top:5px;padding-left:5px}</string>
...
@@ -414,7 +414,7 @@ padding-top:5px;padding-left:5px}</string>
<string/>
<string/>
</property>
</property>
<property
name=
"icon"
>
<property
name=
"icon"
>
<iconset
resource=
"res.qrc"
>
<iconset>
<normaloff>
:/icons/icons/login.svg
</normaloff>
:/icons/icons/login.svg
</iconset>
<normaloff>
:/icons/icons/login.svg
</normaloff>
:/icons/icons/login.svg
</iconset>
</property>
</property>
</widget>
</widget>
...
@@ -425,7 +425,7 @@ padding-top:5px;padding-left:5px}</string>
...
@@ -425,7 +425,7 @@ padding-top:5px;padding-left:5px}</string>
<string/>
<string/>
</property>
</property>
<property
name=
"icon"
>
<property
name=
"icon"
>
<iconset
resource=
"res.qrc"
>
<iconset>
<normaloff>
:/icons/icons/register.svg
</normaloff>
:/icons/icons/register.svg
</iconset>
<normaloff>
:/icons/icons/register.svg
</normaloff>
:/icons/icons/register.svg
</iconset>
</property>
</property>
</widget>
</widget>
...
@@ -513,7 +513,34 @@ padding-top:5px;padding-left:5px}</string>
...
@@ -513,7 +513,34 @@ padding-top:5px;padding-left:5px}</string>
</item>
</item>
</layout>
</layout>
</widget>
</widget>
<widget
class=
"QWidget"
name=
"page_3"
/>
<widget
class=
"QWidget"
name=
"page_3"
>
<widget
class=
"QCheckBox"
name=
"checkBox"
>
<property
name=
"geometry"
>
<rect>
<x>
30
</x>
<y>
10
</y>
<width>
71
</width>
<height>
16
</height>
</rect>
</property>
<property
name=
"text"
>
<string>
记住账号
</string>
</property>
</widget>
<widget
class=
"QCheckBox"
name=
"checkBox_2"
>
<property
name=
"geometry"
>
<rect>
<x>
140
</x>
<y>
10
</y>
<width>
71
</width>
<height>
16
</height>
</rect>
</property>
<property
name=
"text"
>
<string>
记住密码
</string>
</property>
</widget>
</widget>
<widget
class=
"QWidget"
name=
"page_4"
>
<widget
class=
"QWidget"
name=
"page_4"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_10"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_10"
>
<item
alignment=
"Qt::AlignHCenter"
>
<item
alignment=
"Qt::AlignHCenter"
>
...
...
main.py
View file @
a7025954
...
@@ -21,8 +21,7 @@ from PyQt5.QtWidgets import (QApplication, QMainWindow, QTableView, QVBoxLayout,
...
@@ -21,8 +21,7 @@ from PyQt5.QtWidgets import (QApplication, QMainWindow, QTableView, QVBoxLayout,
QLabel
,
QFileDialog
)
QLabel
,
QFileDialog
)
from
PyQt5.QtCore
import
Qt
,
QAbstractTableModel
,
QModelIndex
,
QThread
from
PyQt5.QtCore
import
Qt
,
QAbstractTableModel
,
QModelIndex
,
QThread
from
PyQt5.QtGui
import
QColor
from
PyQt5.QtGui
import
QColor
from
PyQt5.QtGui
import
QValidator
,
QRegExpValidator
from
cryptography.fernet
import
Fernet
from
PyQt5.QtCore
import
QRegExp
from
multipleThread.thread_upload
import
Upload_Thread
from
multipleThread.thread_upload
import
Upload_Thread
from
multipleThread.thread_resume
import
Resume_Thread
from
multipleThread.thread_resume
import
Resume_Thread
from
multipleThread.config
import
*
from
multipleThread.config
import
*
...
@@ -52,6 +51,69 @@ uncomplete_json_folder = "./upload_tag"
...
@@ -52,6 +51,69 @@ uncomplete_json_folder = "./upload_tag"
thread_index
=
0
thread_index
=
0
# 密码加密存储类
class
PasswordManager
:
def
__init__
(
self
,
storage_file
=
'data.json'
,
key_file
=
'secret.key'
):
self
.
storage_file
=
storage_file
self
.
key_file
=
key_file
self
.
key
=
self
.
_load_or_create_key
()
self
.
cipher_suite
=
Fernet
(
self
.
key
)
self
.
passwords
=
self
.
_load_passwords
()
def
_load_or_create_key
(
self
):
"""加载或生成加密密钥"""
if
os
.
path
.
exists
(
self
.
key_file
):
with
open
(
self
.
key_file
,
'rb'
)
as
f
:
return
f
.
read
()
else
:
if
os
.
path
.
exists
(
self
.
storage_file
):
os
.
remove
(
self
.
storage_file
)
key
=
Fernet
.
generate_key
()
with
open
(
self
.
key_file
,
'wb'
)
as
f
:
f
.
write
(
key
)
return
key
def
_load_passwords
(
self
):
"""加载已存储的密码"""
if
os
.
path
.
exists
(
self
.
storage_file
):
with
open
(
self
.
storage_file
,
'rb'
)
as
f
:
encrypted
=
f
.
read
()
decrypted
=
self
.
cipher_suite
.
decrypt
(
encrypted
)
return
json
.
loads
(
decrypted
.
decode
())
return
{}
def
_save_passwords
(
self
):
"""加密并保存密码"""
data
=
json
.
dumps
(
self
.
passwords
)
.
encode
()
encrypted
=
self
.
cipher_suite
.
encrypt
(
data
)
with
open
(
self
.
storage_file
,
'wb'
)
as
f
:
f
.
write
(
encrypted
)
def
add_password
(
self
,
service
,
username
,
password
=
""
,
keep_username
=
0
,
keep_password
=
0
):
"""添加/更新密码"""
self
.
passwords
[
service
]
=
{
'username'
:
username
,
'password'
:
password
,
"keep_username"
:
keep_username
,
"keep_password"
:
keep_password
}
self
.
_save_passwords
()
def
get_password
(
self
,
service
):
"""获取密码"""
return
self
.
passwords
.
get
(
service
)
def
delete_password
(
self
,
service
):
"""删除密码"""
if
service
in
self
.
passwords
:
del
self
.
passwords
[
service
]
self
.
_save_passwords
()
return
True
return
False
class
OrderDetail
(
QMainWindow
):
class
OrderDetail
(
QMainWindow
):
_instance
=
None
_instance
=
None
...
@@ -722,13 +784,38 @@ class LoginWindow(QMainWindow):
...
@@ -722,13 +784,38 @@ class LoginWindow(QMainWindow):
self
.
shadow
.
setOffset
(
5
,
5
)
self
.
shadow
.
setOffset
(
5
,
5
)
self
.
shadow
.
setBlurRadius
(
15
)
self
.
shadow
.
setBlurRadius
(
15
)
self
.
shadow
.
setColor
(
QtCore
.
Qt
.
black
)
self
.
shadow
.
setColor
(
QtCore
.
Qt
.
black
)
# 不能只记住密码
self
.
ui
.
checkBox
.
stateChanged
.
connect
(
self
.
remember_name_checked
)
self
.
ui
.
checkBox_2
.
stateChanged
.
connect
(
self
.
remember_password_checked
)
self
.
ui
.
frame
.
setGraphicsEffect
(
self
.
shadow
)
self
.
ui
.
frame
.
setGraphicsEffect
(
self
.
shadow
)
self
.
ui
.
login
.
clicked
.
connect
(
lambda
:
self
.
ui
.
stackedWidget_2
.
setCurrentIndex
(
0
))
self
.
ui
.
login
.
clicked
.
connect
(
lambda
:
self
.
ui
.
stackedWidget_2
.
setCurrentIndex
(
0
))
self
.
ui
.
register_2
.
clicked
.
connect
(
lambda
:
self
.
ui
.
stackedWidget_2
.
setCurrentIndex
(
1
))
self
.
ui
.
register_2
.
clicked
.
connect
(
lambda
:
self
.
ui
.
stackedWidget_2
.
setCurrentIndex
(
1
))
self
.
ui
.
pushButton_4
.
clicked
.
connect
(
self
.
login_in
)
self
.
ui
.
pushButton_4
.
clicked
.
connect
(
self
.
login_in
)
self
.
order_info_page
=
None
self
.
order_info_page
=
None
self
.
pm
=
None
try
:
self
.
pm
=
PasswordManager
()
if
len
(
self
.
pm
.
passwords
)
>
0
:
if
self
.
pm
.
passwords
[
"one"
][
"keep_username"
]:
self
.
ui
.
checkBox
.
setChecked
(
True
)
self
.
ui
.
lineEdit_l_username
.
setText
(
self
.
pm
.
passwords
[
"one"
][
"username"
])
# 记住账户才能记住密码
if
self
.
pm
.
passwords
[
"one"
][
"keep_password"
]:
self
.
ui
.
lineEdit_l_password
.
setText
(
self
.
pm
.
passwords
[
"one"
][
"password"
])
self
.
ui
.
checkBox_2
.
setChecked
(
True
)
except
Exception
as
e
:
print
(
e
)
self
.
show
()
self
.
show
()
def
remember_name_checked
(
self
,
state
):
if
state
==
Qt
.
Unchecked
:
self
.
ui
.
checkBox_2
.
setChecked
(
False
)
def
remember_password_checked
(
self
,
state
):
if
state
==
Qt
.
Checked
:
self
.
ui
.
checkBox
.
setChecked
(
True
)
def
keyPressEvent
(
self
,
event
):
def
keyPressEvent
(
self
,
event
):
if
event
.
key
()
==
Qt
.
Key_Return
or
event
.
key
()
==
Qt
.
Key_Enter
:
if
event
.
key
()
==
Qt
.
Key_Return
or
event
.
key
()
==
Qt
.
Key_Enter
:
self
.
login_in
()
self
.
login_in
()
...
@@ -752,6 +839,26 @@ class LoginWindow(QMainWindow):
...
@@ -752,6 +839,26 @@ class LoginWindow(QMainWindow):
global
user_now
,
token
global
user_now
,
token
user_now
=
account
user_now
=
account
token
=
data
[
'obj'
][
'token'
]
token
=
data
[
'obj'
][
'token'
]
try
:
# 登录成功且记住账号没有被选中
keep_username
=
1
keep_password
=
1
if
not
self
.
ui
.
checkBox
.
checkState
():
self
.
pm
.
add_password
(
"one"
,
""
,
""
,
0
,
0
)
else
:
# 记住密码没选中
if
not
self
.
ui
.
checkBox_2
.
checkState
():
password
=
""
keep_password
=
0
self
.
pm
.
add_password
(
"one"
,
account
,
password
,
keep_username
,
keep_password
)
except
Exception
as
e
:
print
(
e
)
self
.
order_info_page
=
EqipInfoWindow
()
self
.
order_info_page
=
EqipInfoWindow
()
self
.
order_info_page
.
show
()
self
.
order_info_page
.
show
()
self
.
close
()
self
.
close
()
...
...
multipleThread/__pycache__/config.cpython-38.pyc
0 → 100644
View file @
a7025954
File added
multipleThread/__pycache__/thread_resume.cpython-38.pyc
0 → 100644
View file @
a7025954
File added
multipleThread/__pycache__/thread_upload.cpython-38.pyc
0 → 100644
View file @
a7025954
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment