Asterisk - The Open Source Telephony Project  18.5.0
voicemailpwcheck.py
Go to the documentation of this file.
1 #!/usr/bin/env python
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 # Set this to the required minimum length for a password
19 REQUIRED_LENGTH = 6
20 
21 
22 # Regular expressions that match against invalid passwords
23 REGEX_BLACKLIST = [
24  ("(?P<digit>\d)(?P=digit){%d}" % (REQUIRED_LENGTH - 1),
25  "%d consective numbers that are the same" % REQUIRED_LENGTH)
26 ]
27 
28 
29 # Exact passwords that are forbidden. If the string of digits specified here
30 # is found in any part of the password specified, it is considered invalid.
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 # Enforce a password length of at least 6 characters
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)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)