Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys
- def openPassFile():
- try:
- passwordFile = open('hashwork.txt', 'a')
- return passwordFile
- except IOError as e:
- print("I/O Error({0}): {1}".format(e.errno, e.strerror))
- quit
- def closePassFile(passwordFile):
- try:
- passwordFile.close()
- except IOError as e:
- print("I/O Error({0}): {1}".format(e.errno, e.strerror))
- quit
- def randomValue(length):
- import random
- salt_chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
- return ''.join(random.choice(salt_chars) for x in range(length))
- def askforUsername():
- while True:
- print("Please enter the username you would like to use:")
- username = raw_input()
- return username
- def askforPassword():
- import getpass, hashlib
- while True:
- print("What password would you like to create?")
- salt = randomValue(16)
- hashedPassword1 = hashlib.sha256(salt+getpass.getpass()).hexdigest()
- print("nPlease enter password again.")
- hashedPassword2 = hashlib.sha256(salt+getpass.getpass()).hexdigest()
- if hashedPassword1 == hashedPassword2:
- return hashedPassword2, salt
- break
- else:
- print("Your passwords do not match. Please retry")
- def storeInfo(username, hashedPass, salt):
- passwordFile = openPassFile()
- passwordFile.write(username + " | " + hashedPass + " | " + salt + "n")
- closePassFile(passwordFile)
- username = askforUsername()
- hashedPass, salt = askforPassword()
- storeInfo(username, hashedPass, salt)
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement