Код: Выделить всё
method 1 ( login with username and password1 ) :< /code>
$ username = $ _post ['username'];
$ password1 = password_hash ($ _ post ['password1'], password_default) < /code>;
method 2 ( login with a file ) :< /code>
$ password2 = hash ('sha3-512', $ _post ['password2']) < /code>;
В первом методе, потому что пароль (пароль1) < /code> сохраняется с помощью пароля_hash < /code>, мы можем получить к нему допустимо через США и выполнить версию. Но во втором методе невозможно сохранить пароль (пароль2) 2 - The password (password2) is extracted from this file on the client side using the following code and then stored :
Код: Выделить всё
document.getElementById("file").addEventListener("change", function (event) {
const filereader = new FileReader();
filereader.onload = function () {
var filedata = filereader.result.split(',')[1];
const datalength = filedata.length;
filedata = filedata.slice(Math.round(((datalength * 2) / 9)) - 100, Math.round(((datalength * 2) / 9)) + 100) + filedata.slice(Math.round(((datalength * 5) / 9)) - 100, Math.round(((datalength * 5) / 9)) + 100) + filedata.slice(Math.round(((datalength * 8) / 9)) - 100, Math.round(((datalength * 8) / 9)) + 100);
if (/^[a-zA-Z0-9+=/]*$/.test(filedata)) {
console.log(filedata);
//Sending filedata (password2) via Ajax
}
};
filereader.readAsDataURL(event.target.files[0]);
});
< /code>
< /div>
< /div>
< /p>
if (isset($_POST['register']) && !empty($_POST['password2']) && preg_match('/^[a-zA-Z0-9+=\/]*$/', $_POST['password2']) && mb_strlen($_POST['password2'], 'UTF-8') prepare("SELECT username FROM table WHERE password2=?");
$select->execute([hash('sha3-512', $_POST['password2'])]);
$select = $select->fetch(PDO::FETCH_ASSOC);
if ($select === false) {
$update = $conn->prepare("UPDATE table SET password2=? WHERE username=?");
$update->execute([hash('sha3-512', $_POST['password2']), $_POST['username']]);
//...
}
$conn = null;
}
if (isset($_POST['login']) && !empty($_POST['password2']) && preg_match('/^[a-zA-Z0-9+=\/]*$/', $_POST['password2']) && mb_strlen($_POST['password2'], 'UTF-8') prepare("SELECT username FROM table WHERE password2=?");
$select->execute([hash('sha3-512', $_POST['password2'])]);
$select = $select->fetch(PDO::FETCH_ASSOC);
$conn = null;
if ($select !== false) {
//...
}
}
Код: Выделить всё
move_uploaded_fileПочему второй метод более безопасен:
Второй метод: < /strong>
разрешенные символы: 64 Total → A-Z (26 букв нижних регистра) A-Z (26 averscare Letters) 0-9 (10 цифр) + /(2 специальных символов)
Length: ровно 600).Total Possibilities : 10^1084< /code>
Первый метод: < /strong>
username:
разрешенные символы: 36 Total → A-z (26 букв) + 0-9 (10 цифр)
длина: 70 до 32 символов
password:
. A-Z (26 прописных букв) 0-9 (10 цифр)!@#$%^&* (8 специальных символов)
длина: ровно 32 символа
Total Possibilities : 2.33 * 10^108< /code>
10^1084 / 2.33 * 10^108 = 10^976< /code>
This means :[/b] There is no problem with extracting the password on the client side, or should we be worried that the password (password2) column has a unique index.
Подробнее здесь: https://stackoverflow.com/questions/797 ... ing-a-file
Мобильная версия