Asterisk - The Open Source Telephony Project GIT-master-2de1a68
voicemailpwcheck.py
Go to the documentation of this file.
1#!/usr/bin/env python
2''' Sample externpasscheck script for use with voicemail.conf
3
4Copyright (C) 2010, Digium, Inc.
5Russell Bryant <russell@digium.com>
6
7The externpasscheck option in voicemail.conf allows an external script to
8validate passwords when a user is changing it. The script can enforce password
9strength rules. This script is an example of doing so and implements a check
10on password length, a password with too many identical consecutive numbers, or
11a password made up of sequential digits.
12'''
13
14import sys
15import re
16
17
18# Set this to the required minimum length for a password
19REQUIRED_LENGTH = 6
20
21
22# Regular expressions that match against invalid passwords
23REGEX_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# 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.
31PW_BLACKLIST = [
32 "123456",
33 "234567",
34 "345678",
35 "456789",
36 "567890",
37 "098765",
38 "987654",
39 "876543",
40 "765432",
41 "654321"
42]
43
44
45mailbox, context, old_pw, new_pw = sys.argv[1:5]
46
47# Enforce a password length of at least 6 characters
48if 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
53for regex, error in REGEX_BLACKLIST:
54 if re.search(regex, new_pw):
55 print("INVALID: %s" % error)
56 sys.exit(0)
57
58for 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
63print("VALID")
64
65sys.exit(0)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)