fallout-term/fallout_login.py

85 lines
2.5 KiB
Python
Raw Normal View History

2015-05-26 21:37:25 +00:00
import curses
2015-05-27 01:11:31 +00:00
from fallout_functions import slowWrite
from fallout_functions import INPUT_PAUSE
from fallout_functions import TYPE_DELAY
from fallout_functions import upperInput
from fallout_functions import HIDDEN_MASK
2015-05-27 01:11:31 +00:00
################## text strings ######################
HEADER_TEXT = 'WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK'
2015-05-26 21:37:25 +00:00
PASSWORD_PROMPT = 'ENTER PASSWORD NOW'
2015-05-26 21:37:25 +00:00
PASSWORD_ERROR = 'INCORRECT PASSWORD, PLEASE TRY AGAIN'
2015-05-26 21:37:25 +00:00
################## global "constants" ################
2015-05-26 21:37:25 +00:00
ENTRY = 'LOGON '
2015-05-26 21:37:25 +00:00
################## functions #########################
def runLogin(scr, hardMode, username, password):
2015-05-26 21:37:25 +00:00
"""
Start the login process
2015-05-26 21:37:25 +00:00
hardMode - boolean indicating whether the user has to enter the username
and password or if they are entered automatically
username - the username to log in
password - the password to log in
Returns true if hardMode == false or if the user entered the correct string
2015-05-26 21:37:25 +00:00
"""
2015-05-27 01:11:31 +00:00
curses.use_default_colors()
scr.erase()
scr.move(0, 0)
2015-05-26 21:37:25 +00:00
curses.noecho()
scr.scrollok(True)
slowWrite(scr, HEADER_TEXT + '\n\n')
if hardMode:
# use must enter the correct text to proceed
entry = ''
while entry.upper() != ENTRY.upper() + username.upper():
slowWrite(scr, '> ')
entry = upperInput(scr)
else:
# input is entered for them
slowWrite(scr, '> ')
curses.napms(INPUT_PAUSE)
slowWrite(scr, ENTRY + username.upper() + '\n', TYPE_DELAY)
slowWrite(scr, '\n' + PASSWORD_PROMPT + '\n\n')
if hardMode:
# use must enter the correct text to proceed
entry = ''
while entry.upper() != password.upper():
if entry:
slowWrite(scr, PASSWORD_ERROR + '\n\n')
slowWrite(scr, '> ')
entry = upperInput(scr, True)
else:
# input is entered for them
slowWrite(scr, '> ')
curses.napms(INPUT_PAUSE)
password_stars = HIDDEN_MASK * len(password)
slowWrite(scr, password_stars + '\n', TYPE_DELAY)
2015-05-26 21:37:25 +00:00
curses.napms(500)
def beginLogin(hardMode, username, password):
2015-05-26 21:37:25 +00:00
"""
Initialize curses and start the login process
hardMode - boolean indicating whether the user has to enter the username
and password or if they are entered automatically
username - the username to log in
password - the password to log in
Returns true if hardMode == false or if the user entered the correct string
2015-05-26 21:37:25 +00:00
"""
res = curses.wrapper(runLogin, hardMode, username, password)
return res