Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Terminal:
- def __init__(self):
- self.user = None
- self.users = {}
- self.run = False
- def check_login(self):
- if self.user in self.users.keys():
- return True
- else:
- return self.do_login()
- def do_login(self):
- username = raw_input('Username: ')
- password = raw_input('Password: ')
- if username in self.users.keys():
- if password == self.users[username]:
- print 'login ok!'
- print 'Welcome %s!' % (username)
- self.user = username
- return True
- print 'login failed!'
- return False
- def commandline(self):
- cmd = raw_input('INPUT# ')
- if cmd == 'logout':
- print 'Bye!'
- self.user = None
- if cmd == 'quit':
- self.run = False
- def main(self):
- self.run = True
- while self.run:
- if self.check_login(): self.commandline()
- term = Terminal()
- term.users = { 'ndakota':'transltr', 'elite':'awesum' }
- term.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement