/**
  *
  *
  * @param string  $username
  * @param int     $len      (optional) default 10
  * @return string random string of $len chars
  */
 public static function generate($username, $len = 10)
 {
     $pinpass = new PINPassword(array('username' => $username, 'phrase' => 'ignored'));
     $str = '';
     $chars = array();
     $nchars = count(self::$gen_chars);
     while (!$pinpass->validate($username, $str)) {
         $chars = array();
         for ($i = 0; $i <= $len - 1; $i++) {
             $r = rand(0, $nchars - 1);
             $chars[$i] = self::$gen_chars[$r];
         }
         $str = implode('', $chars);
     }
     return $str;
 }
 /**
  *
  *
  * @param unknown $login_name
  * @param unknown $password
  * @return unknown
  */
 protected function validate_password($login_name, $password)
 {
     $pinpass = new PINPassword(array('username' => $login_name, 'phrase' => $password));
     if (!$pinpass->validate()) {
         $this->form_validation_error = 'Password ' . $pinpass->get_error();
         return false;
     }
     return true;
 }
$user = Doctrine::getTable('User')->findOneBy('user_username', $username);
if (!$user) {
    $user = new User();
    $user->user_username = $username;
    $user->user_first_name = '[First]';
    $user->user_last_name = '[Last]';
    $user->user_cre_dtim = air2_date();
    $user->user_cre_user = 1;
    // system user
    $user->user_uuid = air2_generate_uuid();
    $user->user_type = 'A';
    // system type
    $user->user_status = 'A';
    // active
    echo "AIR2 User '{$username}' not found!\n";
    echo "Enter new password to create User. (Blank to cancel)\n > ";
} else {
    echo "Enter new password:\n > ";
}
$userpass = trim(fgets(STDIN));
$pinpass = new PINPassword(array('username' => $username, 'phrase' => $userpass));
if (!$pinpass->validate()) {
    die("Password " . $pinpass->get_error() . "\n");
}
if (strlen($userpass) > 0) {
    $user->user_password = $userpass;
    $user->save();
    echo "Password changed for user " . $user->user_username . " uuid " . $user->user_uuid . "\n";
} else {
    echo "No password specified --- all changes cancelled\n";
}