Esempio n. 1
0
 /**
  * Installation of first Offiria admin user
  */
 public function installAdmin(&$db, $username, $password, $email, $configs)
 {
     $salt = UserHelper::genRandomPassword(32);
     $crypt = UserHelper::getCryptedPassword($password, $salt);
     $password = $crypt . ':' . $salt;
     //$table = $configs->getValue('dbprefix') . 'users';
     $table = $this->_prefix . 'users';
     $date = date("Y-m-d H:i:s");
     $query = "INSERT INTO `{$table}` (id, name, username, email, password, sendEmail, registerDate, lastvisitDate, params) " . "VALUES(42, '{$username}', '{$username}', '{$email}', '{$password}', 1, '{$date}', '{$date}', '')";
     try {
         $stmt = $db->prepare($query);
         $stmt->execute();
     } catch (RuntimeException $e) {
         return false;
     }
     // install anon user
     $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
     $pass = '';
     for ($i = 0; $i < 8; $i++) {
         $n = rand(0, count($alphabet) - 1);
         $pass[$i] = $alphabet[$n];
     }
     $pass = $pass . ':' . $salt;
     $query = "INSERT INTO `{$table}` (id, name, username, email, password, sendEmail,  block, registerDate, lastvisitDate, params) " . "VALUES(43, 'Anonymous', 'anon', '*****@*****.**', '{$pass}', 1,  1, '{$date}', '{$date}', '')";
     try {
         $stmt = $db->prepare($query);
         $stmt->execute();
     } catch (RuntimeException $e) {
         return false;
     }
     return true;
 }