Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * Check if a password is extremely common. Preventing use of the most common ..

Decoded Output download

<?php

/**
 * Check if a password is extremely common. Preventing use of the most common
 * passwords is an attempt to mitigate slow botnet attacks against an entire
 * userbase. See T4143 for discussion.
 *
 * @task common Checking Common Passwords
 */
final class PhabricatorCommonPasswords extends Phobject {


/* -(  Checking Common Passwords  )------------------------------------------ */


  /**
   * Check if a password is extremely common.
   *
   * @param   string  Password to test.
   * @return  bool    True if the password is pathologically weak.
   *
   * @task common
   */
  public static function isCommonPassword($password) {
    static $list;
    if ($list === null) {
      $list = self::loadWordlist();
    }

    return isset($list[strtolower($password)]);
  }


  /**
   * Load the common password wordlist.
   *
   * @return map<string, bool>  Map of common passwords.
   *
   * @task common
   */
  private static function loadWordlist() {
    $root = dirname(phutil_get_library_root('phabricator'));
    $file = $root.'/externals/wordlist/password.lst';
    $data = Filesystem::readFile($file);

    $words = phutil_split_lines($data, $retain_endings = false);

    $map = array();
    foreach ($words as $key => $word) {
      // The wordlist file has some comments at the top, strip those out.
      if (preg_match('/^#!comment:/', $word)) {
        continue;
      }
      $map[strtolower($word)] = true;
    }

    // Add in some application-specific passwords.
    $map += array(
      'phabricator' => true,
      'phab' => true,
      'devtools' => true,
      'differential' => true,
      'codereview' => true,
      'review' => true,
    );

    return $map;
  }

}
 ?>

Did this file decode correctly?

Original Code

<?php

/**
 * Check if a password is extremely common. Preventing use of the most common
 * passwords is an attempt to mitigate slow botnet attacks against an entire
 * userbase. See T4143 for discussion.
 *
 * @task common Checking Common Passwords
 */
final class PhabricatorCommonPasswords extends Phobject {


/* -(  Checking Common Passwords  )------------------------------------------ */


  /**
   * Check if a password is extremely common.
   *
   * @param   string  Password to test.
   * @return  bool    True if the password is pathologically weak.
   *
   * @task common
   */
  public static function isCommonPassword($password) {
    static $list;
    if ($list === null) {
      $list = self::loadWordlist();
    }

    return isset($list[strtolower($password)]);
  }


  /**
   * Load the common password wordlist.
   *
   * @return map<string, bool>  Map of common passwords.
   *
   * @task common
   */
  private static function loadWordlist() {
    $root = dirname(phutil_get_library_root('phabricator'));
    $file = $root.'/externals/wordlist/password.lst';
    $data = Filesystem::readFile($file);

    $words = phutil_split_lines($data, $retain_endings = false);

    $map = array();
    foreach ($words as $key => $word) {
      // The wordlist file has some comments at the top, strip those out.
      if (preg_match('/^#!comment:/', $word)) {
        continue;
      }
      $map[strtolower($word)] = true;
    }

    // Add in some application-specific passwords.
    $map += array(
      'phabricator' => true,
      'phab' => true,
      'devtools' => true,
      'differential' => true,
      'codereview' => true,
      'review' => true,
    );

    return $map;
  }

}

Function Calls

None

Variables

None

Stats

MD5 f1c278913475dd4c4a82c038a8322a94
Eval Count 0
Decode Time 147 ms