#!/usr/bin/python
"""
Ask password multiple times, making sure user enters the
first entered password multiple times correctly
"""

import sys
import signal
import getpass

correct = 0
attempts = 0

def results():
    print """
Password trainer results
 attempts: %d
  correct: %d
""" % (attempts, correct)
    sys.exit(0)

def SIGINT(signum, frame):
    sys.stderr.write('Interrupted')
    results()
signal.signal(signal.SIGINT, SIGINT)

base = getpass.getpass('Enter correct password: ')
while True:
    try:
        value = getpass.getpass('Enter password: ')
    except EOFError:
        results()

    attempts += 1
    if value == base:
        correct += 1 
    else:
        print 'Invalid password'

