-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathuserpw.py
More file actions
75 lines (61 loc) · 1.54 KB
/
userpw.py
File metadata and controls
75 lines (61 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# coding:utf-8
'''
欢迎参加黄哥python远程视频培训,
帮你完成从不会写代码到会写代码解决问题的过渡。
https://github.com/pythonpeixun/article/blob/master/index.md
咨询qq:1465376564
黄哥Python培训 黄哥改写
Python 3
P175页代码
Python3 Removed dict.has_key() – use the in operator instead.
'''
db = {}
def newuser():
prompt = 'login desired: '
while True:
name = input(prompt)
if name in db:
prompt = 'name taken, try another: '
continue
else:
break
pwd = input('passwd: ')
db[name] = pwd
def olduser():
name = input('login: ')
pwd = input('passwd: ')
passwd = db.get(name)
if passwd == pwd:
pass
else:
print('login incorrect')
return
print('welcome back', name)
def showmenu():
prompt = """
(N)ew User Login
(E)xisting User Login
(Q)uit
Enter choice: """
done = False
while not done:
chosen = False
while not chosen:
try:
choice = input(prompt).strip()[0].lower()
except (EOFError, KeyboardInterrupt):
choice = 'q'
print('\nYou picked: [%s]' % choice)
if choice not in 'neq':
print('invalid menu option, try again')
else:
chosen = True
if choice == 'q':
done = True
if choice == 'n':
newuser()
if choice == 'e':
olduser()
if __name__ == '__main__':
showmenu()