fallout-term/fallout_login.py

87 lines
2.5 KiB
Python
Raw Permalink 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
2024-04-28 15:02:47 +00:00
2015-05-27 01:11:31 +00:00
################## text strings ######################
2024-04-28 15:02:47 +00:00
HEADER_TEXT = "WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK"
2015-05-26 21:37:25 +00:00
2024-04-28 15:02:47 +00:00
PASSWORD_PROMPT = "ENTER PASSWORD NOW"
2015-05-26 21:37:25 +00:00
2024-04-28 15:02:47 +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
2024-04-28 15:02:47 +00:00
ENTRY = "LOGON "
2015-05-26 21:37:25 +00:00
################## functions #########################
2024-04-28 15:02:47 +00:00
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
2024-04-28 15:02:47 +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)
2024-04-28 15:02:47 +00:00
slowWrite(scr, HEADER_TEXT + "\n\n")
if hardMode:
# use must enter the correct text to proceed
2024-04-28 15:02:47 +00:00
entry = ""
while entry.upper() != ENTRY.upper() + username.upper():
2024-04-28 15:02:47 +00:00
slowWrite(scr, "> ")
entry = upperInput(scr)
else:
# input is entered for them
2024-04-28 15:02:47 +00:00
slowWrite(scr, "> ")
curses.napms(INPUT_PAUSE)
2024-04-28 15:02:47 +00:00
slowWrite(scr, ENTRY + username.upper() + "\n", TYPE_DELAY, True)
2024-04-28 15:02:47 +00:00
slowWrite(scr, "\n" + PASSWORD_PROMPT + "\n\n")
if hardMode:
# use must enter the correct text to proceed
2024-04-28 15:02:47 +00:00
entry = ""
while entry.upper() != password.upper():
if entry:
2024-04-28 15:02:47 +00:00
slowWrite(scr, PASSWORD_ERROR + "\n\n")
slowWrite(scr, "> ")
entry = upperInput(scr, True)
else:
# input is entered for them
2024-04-28 15:02:47 +00:00
slowWrite(scr, "> ")
curses.napms(INPUT_PAUSE)
password_stars = HIDDEN_MASK * len(password)
2024-04-28 15:02:47 +00:00
slowWrite(scr, password_stars + "\n", TYPE_DELAY, True)
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