Last change
on this file since 17387 was
14635,
checked in by Henrik Bettermann, 8 years ago
|
Add tool to generate SSHA password hash.
|
File size:
861 bytes
|
Line | |
---|
1 | import hashlib |
---|
2 | import os |
---|
3 | import sys |
---|
4 | from base64 import urlsafe_b64encode as encode |
---|
5 | from base64 import urlsafe_b64decode as decode |
---|
6 | |
---|
7 | def makeSecret(password): |
---|
8 | salt = os.urandom(4) |
---|
9 | h = hashlib.sha1(password) |
---|
10 | h.update(salt) |
---|
11 | return "{SSHA}" + encode(h.digest() + salt) |
---|
12 | |
---|
13 | def checkPassword(password, challenge_password): |
---|
14 | challenge_bytes = decode(challenge_password[6:]) |
---|
15 | digest = challenge_bytes[:20] |
---|
16 | salt = challenge_bytes[20:] |
---|
17 | hr = hashlib.sha1(password) |
---|
18 | hr.update(salt) |
---|
19 | return digest == hr.digest() |
---|
20 | |
---|
21 | if __name__=='__main__': |
---|
22 | if len(sys.argv) < 3: |
---|
23 | print 'Usage: %s <encode or check> <password> <ssha string>' % __file__ |
---|
24 | sys.exit(1) |
---|
25 | if sys.argv[1] == 'encode': |
---|
26 | print makeSecret('%s' % sys.argv[2]) |
---|
27 | if sys.argv[1] == 'check': |
---|
28 | print checkPassword('%s' % sys.argv[2], '%s' % sys.argv[3]) |
---|
Note: See
TracBrowser for help on using the repository browser.