generateRandomString() 최종 공개 메소드

Get random string
final public generateRandomString ( integer $length = 12, string $allowed_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ) : string
$length integer
$allowed_chars string
리턴 string
예제 #1
0
 /**
  * Generate user action token
  *
  * @param Newscoop\Entity\User $user
  * @param string $action
  * @return string
  */
 public function generateToken(User $user, $action = 'any')
 {
     $token = $user->generateRandomString(self::TOKEN_LENGTH);
     $this->em->persist(new UserToken($user, $action, $token));
     $this->em->flush();
     return $token;
 }
예제 #2
0
 /**
  * Save instance config (to files and database)
  *
  * @param array      $config
  * @param Connection $connection
  */
 public function saveInstanceConfig($config, $connection)
 {
     // Set site title
     $sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'SiteTitle'";
     $stmt = $connection->prepare($sql);
     $stmt->bindValue(1, $config['site_title']);
     $stmt->execute();
     $sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'EmailFromAddress' OR varname = 'EmailContact'";
     $stmt = $connection->prepare($sql);
     $stmt->bindValue(1, $config['user_email']);
     $stmt->execute();
     // Set admin user
     $user = new User();
     $salt = $user->generateRandomString();
     $password = implode(User::HASH_SEP, array(User::HASH_ALGO, $salt, hash(User::HASH_ALGO, $salt . $config['recheck_user_password'])));
     $sql = "UPDATE liveuser_users SET Password = ?, EMail = ?, time_updated = NOW(), time_created = NOW(), status = '1', is_admin = '1' WHERE id = 1";
     $stmt = $connection->prepare($sql);
     $stmt->bindValue(1, $password);
     $stmt->bindValue(2, $config['user_email']);
     $stmt->execute();
     $sql = "UPDATE SystemPreferences SET value = ? WHERE varname = 'SiteSecretKey'";
     $stmt = $connection->prepare($sql);
     $stmt->bindValue(1, sha1($config['site_title'] . mt_rand()));
     $stmt->execute();
     $sql = "INSERT INTO SystemPreferences (`varname`, `value`, `last_modified`) VALUES ('installation_id', ?, NOW())";
     $stmt = $connection->prepare($sql);
     $stmt->bindValue(1, sha1($config['site_title'] . mt_rand()));
     $stmt->execute();
     $result = $this->setupHtaccess();
     if (!empty($result)) {
         throw new IOException(implode(" ", $result) . " Most likely it's caused by wrong permissions.");
     }
 }