Пример #1
0
    def log_in_request(self, message):
        """ Processes a login request recieved for the client.

        arguments:
            message: expected message is an array on the following format:
                ['Log-in Request', Username, Password]
        """
        username = message[1]
        password = message[2]
        user_exists, password_correct = database.authenticate_user(
            username, password)

        if user_exists and password_correct:
            print('User authenticated')
            self.send_text('Found')
        elif user_exists:
            print('Authentication failure')
            print('Password incorrect')
            self.send_text('Password incorrect')
        else:
            print('Authentication failure')
            print('User doesnt exist')
            self.send_text('Not found')

        self.username, self.password = username, password
        self.logger.info('User access authenticated {}'.format(self.username))
Пример #2
0
def login():
    print("********** Login **********")

    account_number_from_user = input("What is your account number? \n")

    is_valid_account_number = validation.account_number_validation(
        account_number_from_user)

    if is_valid_account_number:

        password = getpass("What is your password \n")

        user = database.authenticate_user(account_number_from_user, password)

        if user:
            import datetime
            now = datetime.datetime.now()
            print("Current date and time : ")
            print(now.strftime("%Y-%m-%d %H:%M:%S"))
            # print('Welcome %s' %name)
            # print('These are the available options:')
            # print('1. Withdrawal')
            # print('2. Cash Deposit')
            # print('3. Check Balance')
            # print('4. Complaint')
            bank_operation(user)

        else:
            print('Password Incorrect, please try again')
            login()

    else:
        print('Account not found, please try again')
        login()
Пример #3
0
def login():
    print("\n\n######### Login #########\n")

    try:
        account_number = int(input("Please enter your account number\n"))
    except:
        print("Invalid account number")
    else:
        password = getpass("Please enter your password\n")

        # check if account_number/password combination exists in database
        if (database.authenticate_user(account_number, password)):
            # convert user account information to array
            user_account = str.split(
                database.get_account_details(account_number), ",")
            database.create_auth_session(account_number)
            dt = datetime.now()
            dt_time = dt.strftime("%H:%M:%S")
            dt_date = dt.strftime("%m/%d/%Y")
            print("\nWelcome %s %s. Logged in at %s on %s" %
                  (user_account[0], user_account[1], dt_time, dt_date))
            bank_menu(account_number, user_account)

    print("You have entered an incorrect account number or password")
    # if user enters 3 or more incorrect passwords, take back to main menu
    global incorrect_login_count
    incorrect_login_count += 1
    if (incorrect_login_count >= 3):
        incorrect_login_count = 0
        print(
            "User name and password have been entered incorrectly too many times. Returning to main screen"
        )
        init()

    login()
Пример #4
0
def login():
    print("======= Login =========")

    account_number_from_user = input("What is your account number?\n")

    is_valid_account_number = validation.account_number_validation(
        account_number_from_user)

    if is_valid_account_number:

        password = getpass("what is your password? \n")

        user = database.authenticate_user(
            account_number_from_user,
            password,
        )

        if user:
            bank_operation(user)

        print("Invalid account or password")
        login()

    else:
        print(
            "Account number invalid. Please check that you entered exactly 10 digits"
        )
        init()
Пример #5
0
def new_transaction():
    values = request.get_json()
    print(values)
    # Check that the required fields are in the POST'ed data
    required = ['voter', 'voted_for', 'private_key']

    if not all(k in values for k in required):
        return 'Missing values', 400

    # Check user credentials by matching private and public keys
    if not authenticate_user(values['voter'], values['private_key']):
        # Status 401: Unauthorized
        print("User does not exist in voter list/incorrect auth")
        return jsonify("Authorization Error"), 401

    # Create a new Transaction, ensure vote of same candidate not in queue
    index = blockchain.new_transaction(values['voter'], values['voted_for'])
    if not index:
        return jsonify("Error: Vote already in Queue"), 406

    # Use zero knowledge proof to verify transaction
    if not blockchain.verify_transactions(values['voter']):
        # if there is a invalid transaction
        # return status code 406: Not Acceptable
        print("ERROR: Invalid transaction")
        return jsonify("Transaction Error: Invalid trasnaction"), 406

    response = {'message': f'Transaction will be added to Block {index}'}
    return jsonify(response), 201
Пример #6
0
def confirm(token):
    #change this you dummy
    email = security.confirm_token(token)
    if email:
        try:
            database.authenticate_user(email)
        except AssertionError:
            return render_template("home.html", correct={"login":True}, bad_login=True, error="User not found.", resend_auth=False)
    else:
        flash("Expired or invalid token.", "danger")
        return render_template("home.html", correct={"login":True}, bad_login=True, error="Expired or invalid token.", resend_auth=True)
    session["email"] = email
    session["access"] = database.get_access(session["email"])
    session["gitlink"] = database.get_git_link(session["email"])
    session["location"] = database.get_location(session["email"])
    return redirect(url_for("login_home", access=session["access"]))
Пример #7
0
def login():
    print("**** Login ****")

    account_number_user = input("What is your Account Number? \n")

    # Validate the account number from user input
    is_valid_account_number = validation.account_number_validation(
        account_number_user)

    # If account number from user input passes, get password
    if is_valid_account_number:

        # Hiding the user's password when typing it in the commandline
        password = getpass("What is your password? \n")
        # Check if user's account number and password exist in the database
        user = database.authenticate_user(account_number_user, password)

        if user:
            # Need to create file in auth_session/ here
            current_date_time = datetime.now()
            formatted_date_time = current_date_time.strftime(
                "%m/%d/%y %H:%M:%S")
            #print("Last login at %s \n" % formatted_date_time)
            latest_login = database.user_login_timestamp(
                account_number_user, formatted_date_time)
            # If the account number and password exist in the database, carry out bank operations
            bank_operations(account_number_user, user)
        else:
            print("Invalid Account Number or Password.")
            login()

    else:
        # Account number from user input didn't pass validation
        print("Account Number Invalid: Check that you have up to 10 digits.")
        init()
Пример #8
0
def login():
    print("****** Login ******")

    account_number_from_user = input("Please enter your account number. \n")

    is_valid_account_number = validate.account_number_validation(
        account_number_from_user)

    if is_valid_account_number:
        password = getpass("Please enter your password. \n")

        user = database.authenticate_user(account_number_from_user, password)

        if user:
            bank_operations(user)

        print("Invalid account or password")
        login()
    else:
        print("Account number invalid")
        print("Account should be only digits and 10 digits long.")
        init()
Пример #9
0
 def authenticate_user(self, user_details):
     return db.authenticate_user(self.db_cursor, user_details)