| 1 |
|
| 2 |
''' Sample externpasscheck script for use with voicemail.conf |
| 3 |
|
| 4 |
Copyright (C) 2010, Digium, Inc. |
| 5 |
Russell Bryant <[email protected]> |
| 6 |
|
| 7 |
The externpasscheck option in voicemail.conf allows an external script to |
| 8 |
validate passwords when a user is changing it. The script can enforce password |
| 9 |
strength rules. This script is an example of doing so and implements a check |
| 10 |
on password length, a password with too many identical consecutive numbers, or |
| 11 |
a password made up of sequential digits. |
| 12 |
''' |
| 13 |
|
| 14 |
import sys |
| 15 |
import re |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
REQUIRED_LENGTH = 6 |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
REGEX_BLACKLIST = [ |
| 24 |
("(?P<digit>\d)(?P=digit){%d}" % (REQUIRED_LENGTH - 1), |
| 25 |
"%d consecutive numbers that are the same" % REQUIRED_LENGTH) |
| 26 |
] |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
PW_BLACKLIST = [ |
| 32 |
"123456", |
| 33 |
"234567", |
| 34 |
"345678", |
| 35 |
"456789", |
| 36 |
"567890", |
| 37 |
"098765", |
| 38 |
"987654", |
| 39 |
"876543", |
| 40 |
"765432", |
| 41 |
"654321" |
| 42 |
] |
| 43 |
|
| 44 |
|
| 45 |
mailbox, context, old_pw, new_pw = sys.argv[1:5] |
| 46 |
|
| 47 |
|
| 48 |
if len(new_pw) < REQUIRED_LENGTH: |
| 49 |
print("INVALID: Password is too short (%d) - must be at least %d" % \ |
| 50 |
(len(new_pw), REQUIRED_LENGTH)) |
| 51 |
sys.exit(0) |
| 52 |
|
| 53 |
for regex, error in REGEX_BLACKLIST: |
| 54 |
if re.search(regex, new_pw): |
| 55 |
print("INVALID: %s" % error) |
| 56 |
sys.exit(0) |
| 57 |
|
| 58 |
for pw in PW_BLACKLIST: |
| 59 |
if new_pw.find(pw) != -1: |
| 60 |
print("INVALID: %s is forbidden in a password" % pw) |
| 61 |
sys.exit(0) |
| 62 |
|
| 63 |
print("VALID") |
| 64 |
|
| 65 |
sys.exit(0) |