Guest User

Untitled

a guest
Jun 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public function register( $id, $password, $other = array() ){
  2. if( $this->userExists($id) || (isset($other['email']) && $this->userExists($other['email'])) ){
  3. return "exists";
  4. }else{
  5. $randomSalt = $this->rand_string(20);
  6. $saltedPass = hash('sha256', "{$password}{$this->passwordSalt}{$randomSalt}");
  7.  
  8. if( count($other) == 0 ){
  9. /* Если другие поля не указаны, выполните запрос по умолчанию */
  10. $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`) VALUES(:username, :password, :passwordSalt)");
  11. }else{
  12. /* если есть другие поля для добавления значения, сделайте запрос и свяжите значения в соответствии с ним */
  13. $keys = array_keys($other);
  14. $columns = implode(",", $keys);
  15. $colVals = implode(",:", $keys);
  16. $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`, $columns) VALUES(:username, :password, :passwordSalt, :$colVals)");
  17. foreach($other as $key => $value){
  18. $value = htmlspecialchars($value);
  19. $sql->bindValue(":$key", $value);
  20. }
  21. }
  22. /* Привязка значений по умолчанию */
  23. $sql->bindValue(":username", $id);
  24. $sql->bindValue(":password", $saltedPass);
  25. $sql->bindValue(":passwordSalt", $randomSalt);
  26. $sql->execute();
  27. return true;
  28. }
  29. }
  30.  
  31. $sql = "
  32. INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`)
  33. VALUES(:username, :password, :passwordSalt);
  34. INSERT INTO `another_table`(`username`) VALUE(:username);
  35. ";
Add Comment
Please, Sign In to add comment