0

I have been writing a program that saves passwords in hash form, but I am trying to get a value from within my file which stores a value for the salt. For some reason, it doesn't seem to work. Here is my code:

hashpass = hashlib.sha256()
salt = ['hbjGVY0Kj07,kbjgvhjb,ZsGhnBi0lp]

for line in login:
            usr = input()
            pas = input()
            log = line.split(',')
            if usr in line:
                x = line
                salt_num = int(x[2])
                setpass = str(pas + salt[salt_num])
                hashpass.update(setpass.encode('utf-8'))

I have tried everything, but still no results when I concatenate the string, I just get the value of pas

M S
  • 15
  • 3

2 Answers2

0

Here is what I tried and it works. The code you have shared has some issue that I would request you to cross check with original code.

import hashlib
hashpass = hashlib.sha256()
salt = ['hbjGVY0Kj07','kbjgvhjb','ZsGhnBi0lp']
login = ["user,68a782faf939dfa370345934d255101926b7f59b3a65ab7db5b0bc6f78ec25e5,0"]

for line in login:
            #print(line)
            usr = input()     # I input "user"
            pas = input()     # I input "qwerty"
            log = line.split(',')
            #print(log)
            if usr in line:
                x = log
                salt_num = int(x[2])
                setpass = str(pas + salt[salt_num])
                print(setpass)
                hashpass.update(setpass.encode('utf-8'))

OUTPUT --> qwertyhbjGVY0Kj07

Things I would suggest you to check:

  • All the items in list salt are in quotes, i.e., as string.

  • Login is a list of strings having elements with comma separated value, like I have created.

  • change x=line to x=log inside if condition.

Prashant Kumar
  • 2,057
  • 2
  • 9
  • 22
  • I fixed my program myself but I am getting a different error this time, I will post it as an answer but essentially, I was comparing the hashed password with the user input, I check both variables and they are equal, yet my program says otherwise. – M S Feb 04 '20 at 20:57
0

I have fixed the issue, but am getting different errors when comparing the variable hashpass with log[1], when comparing my program claims that the password is wrong, here is the whole program for reference.

login = open('login.csv','r')
def logging():
    atmptcount = 0
    while atmptcount < 3:
        usr = input('Please enter your username: ')
        pas = input('Please enter your password: ')
        hashpass = hashlib.sha256()
        for line in login:
            log = line.split(',')
            if usr.upper() in line:
                print(log[2])
                salt_num = int(log[2])
                setpass = str(pas + salt[salt_num])
                hashpass.update(setpass.encode('utf-8'))
            if usr == log[0] and hashpass.hexdigest() == log[1]:
                print('correct')
                return True

        print(hashpass.hexdigest())
        print(log[1])
        atmptcount = atmptcount + 1
        print('Sorry you have entered your details incorrectly, please try again')
        login.seek(0)
    print('Sorry, you have reached your maximum login attempts!')
    return False

I have changed the variable names a bit but its the saem concept

M S
  • 15
  • 3