Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <?php
  2.  
  3.     require '/libs/db.php';
  4.  
  5.     $data = $_POST;
  6.     if (isset($data['accounts_create'])) {
  7.     # массив данных username, email, password, password_2
  8.         $errors = array();
  9.         if (trim($data['username']) == '') {
  10.         # проверяем пустое ли поле username
  11.             $errors[] = 'Введите ваше имя аккаунта!';
  12.         }
  13.  
  14.         if (trim($data['email']) == '') {
  15.         # проверяем пустое ли поле email
  16.             $errors[] = 'Введите ваш email!';
  17.         }
  18.  
  19.         if ($data['password'] == '') {
  20.         # проверка поля password
  21.         $password = $errors[] = 'Введите пароль!';
  22.         }
  23.  
  24.         if ($data['password_2'] != $data['password']) {
  25.         # совпадают ли  password == password_2
  26.             $errors[] = 'Пароли не совпадают!';
  27.         }  
  28.  
  29.         if ( R::count('accounts', "login = ?", array($data['username'] )) > 0) {
  30.         $accounts = $errors[] = '- Имя аккаунта занято!';
  31.         }
  32.  
  33.     if ( empty($errors)) { // если нет ошибок записываем данные в mysql
  34.         $user = R::dispense('accounts');
  35.         $user -> login = $data['username'];
  36.         $user -> l2email = $data['email'];
  37.         //$salt = 'saiO2ojHlRWn1Jvj8qEEDPOw/aBs0oWo'; // 30 символов
  38.         $salt = openssl_random_pseudo_bytes(24);
  39.         $hash = base64_encode(hash_pbkdf2('sha1', $data['password'], base64_decode($salt), 1000, 24, true));
  40.         $user -> password = "sha1:1000:$salt:$hash";
  41.         //  algo:iterations:salt:password
  42.         R::store($user);
  43.        
  44.  
  45.         //$hash = base64_encode(hash_pbkdf2('sha1', '$data['password']', base64_decode($salt), 1000, 24, true));
  46.  
  47.         //echo "sha1:1000:$salt:$hash";
  48.  
  49.         //R::store($user);
  50.  
  51.         $done =  '<div style="color: green;">done</div>';
  52.  
  53.     }   else
  54.    
  55.     {
  56.         $errdone = '<div style="color: red;">'.array_shift($errors).'</div>';
  57.     }
  58. }
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement