【发布时间】:2021-09-20 06:26:10
【问题描述】:
我有一个 python 密码管理系统程序,我正在寻找是否可以将其转换为基于 gui 的程序。
程序中的一个 sn-p:
def signup():
f = open(signup_file,'r')
print('Sign-up procedure')
print()
name = str(input('Enter your username (minimum 4 characters, no whitespaces) : '))
if len(name)<4 or ' ' in name:
return 'Invalid username input'
if user_exists(name) == True:
return 'Username already exists. Please choose another username!'
password = str(input('Enter your password (minimum 8 characters, should not contain whitespace or exceed 16 characters): '))
if password == name:
return 'Please dont use the username as the password! '
if ' ' in password or len(password)>16 or len(password)<8:
return 'Invaild password input'
c_password=str(input('Confirm your entered password : '))
#Salted-hashing
salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii')
passhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), salt, 100000)
passhash = binascii.hexlify(passhash)
final_password = (salt + passhash).decode('ascii')
if c_password != password:
return 'Passwords do not match !'
else:
#user_file0 = str(uuid.uuid4().hex)+'.txt' (for random file name)
user_file0 = name + '_file.txt'
fw = open(signup_file,'a')
entry = name + ' ' + final_password + ' ' + user_file0 + '\n'
fw.write(entry)
return 'Sign-up completed'
fw.close()
f.close()
我还有很多其他的功能和一个基于idle的菜单,那么有没有什么方法可以在不重写整个代码的情况下将其转换成gui?
【问题讨论】:
-
对不起,你得从头开始。
-
这是一个常见的问题:如何通过各种人机界面使用相同的处理。答案是低耦合。如果您将算法部分封装在函数和类中,您将能够共享它。但如果更复杂的部分是接口本身,唯一的好处就是可维护性:如果您以后使用不同的密码编码方案,您将在一个地方更改它。
-
@SergeBallesta 抱歉,但这对我的学校项目来说似乎太复杂了????
标签: python user-interface tkinter