create ldap password
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
937d5f0ddc
commit
e0afedf881
1 changed files with 26 additions and 0 deletions
26
ldap-password.py
Normal file
26
ldap-password.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
from base64 import urlsafe_b64encode as encode
|
||||
from base64 import urlsafe_b64decode as decode
|
||||
|
||||
def makeSecret(password):
|
||||
salt = os.urandom(4)
|
||||
h = hashlib.sha1(password)
|
||||
h.update(salt)
|
||||
return "{SSHA}" + encode(h.digest() + salt)
|
||||
|
||||
def checkPassword(challenge_password, password):
|
||||
challenge_bytes = decode(challenge_password[6:])
|
||||
digest = challenge_bytes[:20]
|
||||
salt = challenge_bytes[20:]
|
||||
hr = hashlib.sha1(password)
|
||||
hr.update(salt)
|
||||
return digest == hr.digest()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
print(makeSecret(sys.argv[1]))
|
Loading…
Reference in a new issue