4 * Check if a password is extremely common. Preventing use of the most common
5 * passwords is an attempt to mitigate slow botnet attacks against an entire
6 * userbase. See T4143 for discussion.
8 * @task common Checking Common Passwords
10 final class PhabricatorCommonPasswords
extends Phobject
{
13 /* -( Checking Common Passwords )------------------------------------------ */
17 * Check if a password is extremely common.
19 * @param string Password to test.
20 * @return bool True if the password is pathologically weak.
24 public static function isCommonPassword($password) {
27 $list = self
::loadWordlist();
30 return isset($list[strtolower($password)]);
35 * Load the common password wordlist.
37 * @return map<string, bool> Map of common passwords.
41 private static function loadWordlist() {
42 $root = dirname(phutil_get_library_root('phabricator'));
43 $file = $root.'/externals/wordlist/password.lst';
44 $data = Filesystem
::readFile($file);
46 $words = phutil_split_lines($data, $retain_endings = false);
49 foreach ($words as $key => $word) {
50 // The wordlist file has some comments at the top, strip those out.
51 if (preg_match('/^#!comment:/', $word)) {
54 $map[strtolower($word)] = true;
57 // Add in some application-specific passwords.
59 'phabricator' => true,
62 'differential' => true,