-1

Is it accepted to build a login form where storing password in PHP file?

For example:

Is something like below secure for passwords? assuming that the webserver won't fail and expose the code to browser.

<?php
    if ($_POST["password"] == "mypassword") {
    //some code
?>  

I wanted to know if this particular example is secure, considering the assumption

WPDev
  • 161
  • 9

3 Answers3

2

You should use secure way like below helpful links:

https://secure.php.net/manual/en/function.password-hash.php

https://secure.php.net/manual/en/function.password-verify.php

Here is the example:

// See the password_hash() example to see where this came from.
$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';

if (password_verify($_POST['password'], $hash)) {
     echo 'Password is valid!';
} else {
    echo 'Invalid password.';
}

Hope this helps

Robert
  • 5,703
  • 2
  • 31
  • 32
Therichpost
  • 1,759
  • 2
  • 14
  • 19
1

This approach is discouraged because of many reasons. Most important one being security. You never write password in plain text in the source code because source code is to be checked into the source control, and any one can inspect the file and find the password.

You can create environment variables to store passwords and retrieve it in your PHP code using getenv() method. This will be a secure way to do it, because you are not exposing your sensitive information to the world.

Abdul Fatah
  • 463
  • 6
  • 23
0

No this is not secure. you should use hashing algorithm to make more secure.you can also use hashing with salting.if database is compromised even then also hacker can't see passwords.because when you hash password it can't be decrypt.in simple you cannot change from gibberish to plain text.many users use just one password for every account to resolve this problem you can use hashing and salting

Yashraj Basan
  • 82
  • 1
  • 6