forked from exavolt/python-phpass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
69 lines (50 loc) · 1.59 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import phpass
ok = 0
# Try to use stronger but system-specific hashes, with a possible fallback to
# the weaker portable hashes.
t_hasher = phpass.PasswordHash(8, False)
correct = 'test12345'
hx = t_hasher.hash_password(correct)
print 'Hash: %r' % hx
check = t_hasher.check_password(correct, hx)
if check:
ok += 1
print "Check correct: %r (should be True)" % check
wrong = 'test12346'
check = t_hasher.check_password(wrong, hx)
if not check:
ok += 1
print "Check wrong: %r (should be False)" % check
t_hasher = None
# Force the use of weaker portable hashes.
t_hasher = phpass.PasswordHash(8, True)
hx = t_hasher.hash_password(correct)
print 'Hash: %r' % hx
check = t_hasher.check_password(correct, hx)
if check:
ok += 1
print "Check correct: %r (should be True)" % check
check = t_hasher.check_password(wrong, hx)
if not check:
ok += 1
print "Check wrong: %r (should be False)" % check
# A correct portable hash for 'test12345'.
# Please note the use of single quotes to ensure that the dollar signs will
# be interpreted literally. Of course, a real application making use of the
# framework won't store password hashes within a PHP source file anyway.
# We only do this for testing.
hx = '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0'
print 'Hash: %r' % hx
check = t_hasher.check_password(correct, hx)
if check:
ok += 1
print "Check correct: %r (should be True)" % check
check = t_hasher.check_password(wrong, hx)
if not check:
ok += 1
print "Check wrong: %r (should be False)" % check
if ok == 6:
print "All tests have PASSED"
else:
print "Some tests have FAILED"