/** * Create a new user in the DB * @param object $request request details * @param string $user username * @param string $pass password * @return bool */ public function create($user, $pass) { $this->connect(); $created = false; $sql = $this->dbh->prepare("select username from hm_user where username = ?"); if ($sql->execute(array($user))) { $res = $sql->fetch(); if (!empty($res)) { Hm_Msgs::add("ERRThat username is already in use"); } else { $sql = $this->dbh->prepare("insert into hm_user values(?,?)"); $hash = Hm_Crypt::hash_password($pass); if ($sql->execute(array($user, $hash))) { Hm_Msgs::add("Account created"); $created = true; } } } return $created; }
/** * @preserveGlobalState disabled * @runInSeparateProcess */ public function test_hash_password() { $hash = Hm_Crypt::hash_password('test'); $this->assertTrue(Hm_Crypt::check_password('test', $hash)); }