Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function register( $id, $password, $other = array() ){
- if( $this->userExists($id) || (isset($other['email']) && $this->userExists($other['email'])) ){
- return "exists";
- }else{
- $randomSalt = $this->rand_string(20);
- $saltedPass = hash('sha256', "{$password}{$this->passwordSalt}{$randomSalt}");
- if( count($other) == 0 ){
- /* Если другие поля не указаны, выполните запрос по умолчанию */
- $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`) VALUES(:username, :password, :passwordSalt)");
- }else{
- /* если есть другие поля для добавления значения, сделайте запрос и свяжите значения в соответствии с ним */
- $keys = array_keys($other);
- $columns = implode(",", $keys);
- $colVals = implode(",:", $keys);
- $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`, $columns) VALUES(:username, :password, :passwordSalt, :$colVals)");
- foreach($other as $key => $value){
- $value = htmlspecialchars($value);
- $sql->bindValue(":$key", $value);
- }
- }
- /* Привязка значений по умолчанию */
- $sql->bindValue(":username", $id);
- $sql->bindValue(":password", $saltedPass);
- $sql->bindValue(":passwordSalt", $randomSalt);
- $sql->execute();
- return true;
- }
- }
- $sql = "
- INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`)
- VALUES(:username, :password, :passwordSalt);
- INSERT INTO `another_table`(`username`) VALUE(:username);
- ";
Add Comment
Please, Sign In to add comment