在文本文件中查找哈希值

时间:2015-03-04 20:30:08

标签: python authentication login

我正在尝试使用文本文档验证用户,但没有取得多大成功。有人可以指点我正确的方向吗?这是我的代码。我想要做的是在包含哈希的行上有python外观,然后验证哈希。它能够验证第一个哈希,但之后没有任何内容。有谁知道如何解决这个问题?

def passwordVerify():
    global hashOne
    f = open("maindata.txt")
    s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
    numberOne = userConfirm + 2
    numberTwo = userConfirm + 1
    for line in islice(f, numberTwo, numberOne):
        hashOne = line
    hashStripped = str.rstrip(hashOne)
    hashchecker = sha256_crypt.verify(passWord, hashStripped)
    f.close()
    if hashchecker is True:
        loggedIn()

    else:
        print "Please try again!"
        time.sleep(2.5)
        userLogin()


def userRegister():
    screenClear()
    print "!King of Hearts Registration System!"
    realName = raw_input("What is your real name: ")
    userName = raw_input("Choose a Username: ")
    passWord = getpass.getpass("Please enter a password: ")
    passHash = sha256_crypt.encrypt(passWord)
    writeUser = "\n" + userName + "\n"
    writePass = passHash
    userDB = open("maindata.txt", "a")
    userDB.write(str(writeUser))
    userDB.write(str(writePass))
    userDB.close()
    print passHash
    userLogin()

0 个答案:

没有答案