def runBoot(scr, hardMode): """ Start the boot portion of the terminal hardMode - boolean indicating whether the user has to enter the ENTRY constants, or if they are entered automatically """ curses.use_default_colors() scr.erase() scr.move(0, 0) curses.noecho() scr.scrollok(True) slowWrite(scr, MESSAGE_1 + '\n\n') if hardMode: # use must enter the correct text to proceed entry = '' while entry.upper() != ENTRY_1.upper(): slowWrite(scr, '>') entry = upperInput(scr) else: # input is entered for them slowWrite(scr, '>') curses.napms(INPUT_PAUSE) slowWrite(scr, ENTRY_1 + '\n', TYPE_DELAY) slowWrite(scr, '\n' + MESSAGE_2 + '\n\n') if hardMode: entry = '' while entry.upper() != ENTRY_2.upper(): slowWrite(scr, '>') entry = upperInput(scr) while entry.upper() != ENTRY_3.upper(): slowWrite(scr, '>') entry = upperInput(scr) else: slowWrite(scr, '>') curses.napms(INPUT_PAUSE) slowWrite(scr, ENTRY_2 + '\n', TYPE_DELAY) slowWrite(scr, '>') curses.napms(INPUT_PAUSE) slowWrite(scr, ENTRY_3 + '\n', TYPE_DELAY) slowWrite(scr, '\n' + MESSAGE_3 + '\n\n') if hardMode: entry = '' while entry.upper() != ENTRY_4.upper(): slowWrite(scr, '>') entry = upperInput(scr) else: slowWrite(scr, '>') curses.napms(INPUT_PAUSE) slowWrite(scr, ENTRY_4 + '\n', TYPE_DELAY) curses.napms(INPUT_PAUSE) return True
def runLogin(scr, hardMode, username, password): """ 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 """ curses.use_default_colors() scr.erase() scr.move(0, 0) 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) curses.napms(500)
def userInput(scr, passwords): """ let the user attempt to crack the password scr - curses window returned from curses.initscr() passwords - array of passwords hidden in the symbols """ size = scr.getmaxyx() height = size[0] width = size[1] # set up a pad for user input inputPad = curses.newpad(height, width // 2 + CONST_CHARS) attempts = LOGIN_ATTEMPTS # randomly pick a password from the list pwd = passwords[random.randint(0, len(passwords) - 1)] curses.noecho() while attempts > 0: # move the curser to the correct spot for typing scr.move(height - 1, width // 2 + CONST_CHARS + 1) # scroll user input up as the user tries passwords moveInput(scr, inputPad) guess = upperInput(scr, False, False) cursorPos = inputPad.getyx() # write under the last line of text inputPad.move(cursorPos[0] - 1, cursorPos[1] - 1) inputPad.addstr('>' + guess.upper() + '\n') # user got password right if guess.upper() == pwd.upper(): inputPad.addstr('>Exact match!\n') inputPad.addstr('>Please wait\n') inputPad.addstr('>while system\n') inputPad.addstr('>is accessed.\n') moveInput(scr, inputPad) curses.napms(LOGIN_PAUSE) return pwd # wrong password else: pwdLen = len(pwd) matched = 0 try: for i in range(pwdLen): if pwd[i].upper() == guess[i].upper(): matched += 1 except IndexError: pass # user did not enter enough letters inputPad.addstr('>Entry denied\n') inputPad.addstr('>' + str(matched) + '/' + str(pwdLen) + ' correct.\n') attempts -= 1 # show remaining attempts scr.move(SQUARE_Y, 0) scr.addstr(str(attempts)) scr.move(SQUARE_Y, SQUARE_X) for i in range(LOGIN_ATTEMPTS): if i < attempts: scr.addch(curses.ACS_BLOCK) else: scr.addstr(' ') scr.addstr(' ') # Out of attempts return None
def userInput(scr, passwords): """ let the user attempt to crack the password scr - curses window returned from curses.initscr() passwords - array of passwords hidden in the symbols """ size = scr.getmaxyx() height = size[0] width = size[1] # set up a pad for user input inputPad = curses.newpad(height, width / 2 + CONST_CHARS) attempts = LOGIN_ATTEMPTS # randomly pick a password from the list pwd = passwords[random.randint(0, len(passwords) - 1)] curses.noecho() while attempts > 0: # move the curser to the correct spot for typing scr.move(height - 1, width / 2 + CONST_CHARS + 1) # scroll user input up as the user tries passwords moveInput(scr, inputPad) guess = upperInput(scr, False, False) cursorPos = inputPad.getyx() # write under the last line of text inputPad.move(cursorPos[0] - 1, cursorPos[1] - 1) inputPad.addstr('>' + guess.upper() + '\n') # user got password right if guess.upper() == pwd.upper(): inputPad.addstr('>Exact match!\n') inputPad.addstr('>Please wait\n') inputPad.addstr('>while system\n') inputPad.addstr('>is accessed.\n') moveInput(scr, inputPad) curses.napms(LOGIN_PAUSE) return pwd # wrong password else: pwdLen = len(pwd) matched = 0 try: for i in xrange(pwdLen): if pwd[i].upper() == guess[i].upper(): matched += 1 except IndexError: pass # user did not enter enough letters inputPad.addstr('>Entry denied\n') inputPad.addstr('>' + str(matched) + '/' + str(pwdLen) + ' correct.\n') attempts -= 1 # show remaining attempts scr.move(SQUARE_Y, 0) scr.addstr(str(attempts)) scr.move(SQUARE_Y, SQUARE_X) for i in xrange(LOGIN_ATTEMPTS): if i < attempts: scr.addch(curses.ACS_BLOCK) else: scr.addstr(' ') scr.addstr(' ') # Out of attempts return None