Skip to content

Instantly share code, notes, and snippets.

@msghens
Created November 10, 2017 01:01
Show Gist options
  • Select an option

  • Save msghens/63142812a9ba41c36b278600e3b4b22b to your computer and use it in GitHub Desktop.

Select an option

Save msghens/63142812a9ba41c36b278600e3b4b22b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import hashlib
import secrets
import sys
"""
This method generates the sha1 hex of the password+salt.
"""
def gen_digested_password(pw,salt=secrets.token_hex(4).upper()):
print (salt.encode())
print (len(salt.encode()))
print (sys.getsizeof(salt.encode()))
return (hashlib.sha1(pw.encode() + salt.encode()).hexdigest() + ':' + salt).upper()
"""
This method decodes a ssha-encoded password string, returning the
digest and salt
"""
def decode_ssha_password(ssha_password):
decoded = base64.b64decode(ssha_password.replace("{SSHA}",""))
digest = decoded[0:40]
salt = decoded[40:]
return digest,salt
print(gen_digested_password('helloworld','ZZDK05NS'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment