A
A
aopil2021-07-17 20:23:51
PHP
aopil, 2021-07-17 20:23:51

How to compare API key correctly?

Currently implemented as follows:

$request = "SELECT APIKey, FullName FROM users WHERE UserName = '$USER_NAME'";


if((isset($rs->APIKey) && !empty($rs->APIKey)) && (decrypt($rs->APIKey) == $API_KEY))
{
}


Question: Why not use $encAPIKey = encrypt($API_KEY)and substitute it in the SQL query:
$request = "SELECT APIKey, FullName FROM users WHERE UserName = '$USER_NAME' AND APIKey = '$encAPIKey'";


Perhaps I don’t understand something and there are some moments of security violations, etc.?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-07-17
@ThunderCat

Q: Why not use
Firstly, this way you will not know what the reason is - in the login or in the password, or in both fields. Secondly, it MAY work with keys, but it doesn’t work like that with passwords, there is a different reconciliation algorithm, and it is advisable not to produce entities and create algorithms that are as close as possible in implementation in similar places.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question