Python Forum
Using hashlib for user password
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using hashlib for user password
#1
So I have to hash a user entered password and then write the hashed password to a file. The code I have puts the clear text password into the file not the hash.
This is my code for my function
import hashlib

def writeHashedPswd(password):
    
    
   # try:
        myhash = hashlib.md5(password)
        myfile = open("password.txt", "w")
        myfile.write(password + '/n')
        password = myhash.hexdigest()
        myfile.close()
      
        myfile = open("password.txt", "a")
        myfile.write("an error occured.")
        myfile.close()
Code for program file
import a8

password = raw_input('Enter your password: ')
a8.writeHashedPswd(password)
What am I missing? Thanks!
Reply
#2
At line 9 you are writing the password into the file.
Reply
#3
Do I need to remove line 9 then?
(Mar-02-2018, 07:36 PM)Gribouillis Wrote: At line 9 you are writing the password into the file.
Reply
#4
I don't know what is the purpose of this but hashing a password with md5 is dangerous. Use at least sha256. Which is not safe too. With a proper hardware is not so time-consuming to find the password.

Look at argon2id or argon2i with at least 3-5 passes.

Ah, Homework forum... Sorry!
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
Please use pbkdf2 from hashlib.
Use as 64bit salt and a sha512 as algorithm for example. Md5 is for security a nightmare. Plase tell this your teacher. Don not use md5 to hash passwords.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020