View difference between Paste ID: sqhKSB9a and ifABKXmD
SHOW: | | - or go back to the newest paste.
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 символов
37+
38-
		$salt = openssl_random_pseudo_bytes(24);
38+
		$user -> password = password_hash($data['password'], PASSWORD_BCRYPT);
39-
		$user -> password = base64_encode(hash_pbkdf2('sha1', $data['password'], base64_decode($salt), 1000, 24, true));
39+
40-
		//	algo:iterations:salt:password
40+
		R::store($user);
41-
		R::store($algo.':'.$iterations.':'.$salt.':'.$user);
41+
42-
		
42+
43
44-
		//$hash = base64_encode(hash_pbkdf2('sha1', '$data['password']', base64_decode($salt), 1000, 24, true));
44+
45
	
46-
		//echo "sha1:1000:$salt:$hash";
46+
47
		$errdone = '<div style="color: red;">'.array_shift($errors).'</div>';
48-
		//R::store($user);
48+
49
}
50
51
?>