Python 查找散列';文本文件中的
我正在尝试验证使用文本文档的用户,但没有太多成功。有人能给我指一下正确的方向吗?这是我的密码。我想做的是让python查看包含散列的行,然后验证散列。它能够验证第一个散列,但之后什么也不能验证。有人知道如何解决这个问题吗Python 查找散列';文本文件中的,python,authentication,login,Python,Authentication,Login,我正在尝试验证使用文本文档的用户,但没有太多成功。有人能给我指一下正确的方向吗?这是我的密码。我想做的是让python查看包含散列的行,然后验证散列。它能够验证第一个散列,但之后什么也不能验证。有人知道如何解决这个问题吗 def passwordVerify(): global hashOne f = open("maindata.txt") s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) numberO
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()
从文件中读取的哈希值可能包括行末尾的换行符。在使用它之前,你应该先去掉它,例如使用
str.rstrip()
。但是它也不会验证新注册的用户,我该如何解决这个问题?这是另一个问题,没有人会涉入到代码的海洋中去解决它。