E
E
Evgeny Varianov2018-03-23 22:37:06
PHP
Evgeny Varianov, 2018-03-23 22:37:06

How to display an error in the authorization form with incorrectly entered data?

How to finish checking the login and password during authorization (should give an error - if the data is entered incorrectly)?
I have this code:

if(isset($_POST[login_admin]))
{
if($_POST[login] == $admins[login] || md5($_POST[password]) == $admins[password])
{
if(isset($_POST[me])) {$time = '900000000';} else {$time = '84000';}
setcookie('hash', md5($_POST[password]), time()+$time);
setcookie('login',$_POST[login], time()+$time);
header('Location: index.php');
}
}

It is necessary to finish the feature, which would give an error if the username or password is incorrect.
Thanks to all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ipokos, 2018-03-24
@ipokos

if($_POST[login] == $admins[login] || md5($_POST[password]) == $admins[password])

If in this section $_POST[login] == $admins[login] you are comparing login and password md5($_POST[password]) == $admins[password])
then the condition should not be "or" ( || ) , and "and"( && )
i.e. to start doing this:
Well, to the point of the question:
if(isset($_POST[login_admin]))
{
    if($_POST[login] == $admins[login] && md5($_POST[password]) == $admins[password]){
    if(isset($_POST[me])) {$time = '900000000';} else {$time = '84000';}
        setcookie('hash', md5($_POST[password]), time()+$time);
        setcookie('login',$_POST[login], time()+$time);
        header('Location: index.php');
    }else{
        echo 'Error';
    }
}

ps. well, it would be nice to read:
if else
password_hash - md5 is not relevant at all
Validation of data from the user

E
Evgeniy Varianov, 2018-03-24
@Jykach

I can't make an array with errors. Tell me how to do it in this case? *

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question