Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4.  
  5. def openPassFile():
  6. try:
  7. passwordFile = open('hashwork.txt', 'a')
  8. return passwordFile
  9. except IOError as e:
  10. print("I/O Error({0}): {1}".format(e.errno, e.strerror))
  11. quit
  12.  
  13. def closePassFile(passwordFile):
  14. try:
  15. passwordFile.close()
  16. except IOError as e:
  17. print("I/O Error({0}): {1}".format(e.errno, e.strerror))
  18. quit
  19.  
  20. def randomValue(length):
  21. import random
  22. salt_chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
  23. return ''.join(random.choice(salt_chars) for x in range(length))
  24.  
  25. def askforUsername():
  26. while True:
  27. print("Please enter the username you would like to use:")
  28. username = raw_input()
  29. return username
  30.  
  31. def askforPassword():
  32. import getpass, hashlib
  33. while True:
  34. print("What password would you like to create?")
  35. salt = randomValue(16)
  36. hashedPassword1 = hashlib.sha256(salt+getpass.getpass()).hexdigest()
  37. print("nPlease enter password again.")
  38. hashedPassword2 = hashlib.sha256(salt+getpass.getpass()).hexdigest()
  39. if hashedPassword1 == hashedPassword2:
  40. return hashedPassword2, salt
  41. break
  42. else:
  43. print("Your passwords do not match. Please retry")
  44.  
  45. def storeInfo(username, hashedPass, salt):
  46. passwordFile = openPassFile()
  47. passwordFile.write(username + " | " + hashedPass + " | " + salt + "n")
  48. closePassFile(passwordFile)
  49.  
  50. username = askforUsername()
  51. hashedPass, salt = askforPassword()
  52. storeInfo(username, hashedPass, salt)
  53. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement