Refactor the way error is thrown in ask salt.

This commit is contained in:
Stanislas Dolcini 2018-10-05 19:46:44 +02:00
parent ad07c3fc51
commit b6a989599c

View file

@ -40,16 +40,15 @@ class ConnectionHandler
private function askSalt($login, $lang) private function askSalt($login, $lang)
{ {
setMsgLanguage($lang); setMsgLanguage($lang);
$escaped_login = $mysqli->escape_string($login); $escaped_login = $this->db_Connection->escape_string($login);
if ($stmt = $this->db_Connection->prepare('SELECT Password FROM user WHERE Login=\'?\' LIMIT 1')) { if ($stmt = $this->db_Connection->prepare('SELECT Password FROM user WHERE Login=\'?\' LIMIT 1')) {
if ($stmt = mysqli_prepare('SELECT TOP 1 Password FROM user WHERE Login=\'?\'')) {
$stmt->bind_param("s", $escaped_login); $stmt->bind_param("s", $escaped_login);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($password) or die(errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysqli_error($link))); $stmt->bind_result($password) or die(errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, $this->db_Connection->error));
if ($stmt->num_rows == 1 && $stmt->fetch()) { if ($stmt->fetch() && $stmt->num_rows == 1) {
$salt = get_salt($password); $salt = '1:' . get_salt($password);
} else { } else {
die(errorMsgBlock(2001, $login, 'askSalt')); $salt = errorMsgBlock(2001, $login, 'askSalt');
} }
$stmt->close(); $stmt->close();
} }
@ -113,10 +112,10 @@ class ConnectionHandler
{ {
switch ($command->cmd) { switch ($command->cmd) {
case 'ask': case 'ask':
echo '1:' . askSalt($command->login, $command->submittedLang); echo askSalt($command->login, $command->submittedLang);
break; break;
case 'login-https': case 'login-https':
$salt = askSalt($command->login, $command->submittedLang); $salt = substr(askSalt($command->login, $command->submittedLang), 2);
$generated_password = crypt($command->password, sprintf('$6$rounds=%d$%s$', 5000, $salt)); $generated_password = crypt($command->password, sprintf('$6$rounds=%d$%s$', 5000, $salt));
login($command->login, $generated_password, $command->clientApplication, $command->cp, $command->submittedLang); login($command->login, $generated_password, $command->clientApplication, $command->cp, $command->submittedLang);
break; break;