I have created a small script for work. It's an internal web script but has to be hosted on our public domain so I have created a very small PHP based login system using a login form and a session check. Instead of having to define the password in plain text, can someone show me how to add the password in an encrypted format, without the use of a database or external file?
My login code is posted at the bottom - just above it is the line that I would like to change this password to some kind of encryption so that it cannot be read plaintext should someone gain access to the files, or PHP screws up and starts printing in plain text. I have tried googling and searching SE bu everything is relating to DBs and external conf files.
$logins = array('username' => 'password123');
<?php session_start();
if(isset($_POST['Submit'])){
$logins = array('username' => 'password123');
$Username = isset($_POST['Username']) ? $_POST['Username'] : '';
$Password = isset($_POST['Password']) ? $_POST['Password'] : '';
if (isset($logins[$Username]) && $logins[$Username] == $Password){
$_SESSION['UserData']['Username']=$logins[$Username];
if (isset($_SESSION["login_redirect"])) {
header("Location: " . $_SESSION["login_redirect"]);
unset($_SESSION["login_redirect"]);
} else {
header("Location: index.php");
}
exit;
} else {
/* Login failed display message */
$msg="<span style='color:red'>Invalid Login Details</span>";
}
}
Thanks for any and all help!
p.s. The script is hosted/served from HTTPS and HTTP2 on PHP 7x and apache in case it makes any difference.
Edit:
To start with there is only 1 user and password. there may be additional users in the future. But as it stands now just one is needed for the staff. There is no requirement for logging user actions etc at the moment.
The script will be on a subdomain of a public website which has its own WAF that also protects the sub dir, so things like brute force will be picked up. We also have Mod Security and CSF on the server which will also help out.
The script is being hosted on the public side as the company does not utilize an internal intranet, VPN or LDAP / AD server etc. The script needs to also be accessible outside the office - should the boss decide to work from home or Starbucks...
I only want to secure the password part because it is stored in plaintext inside the login.php file. If someone was to access it on the server or via FTP etc, they would have easy access to the password. And as mentioned should PHP break I do not want to password shown as plaintext on screen either.
So to update my question a little. Can someone give me starting pointers for replacing the password with a hashed password system instead?
Again I understand a number of people on here will suggest using corporate intranets, VPNs, dedicated platforms blah blah, please understand this is a small company and an even smaller project. Things like staff leaking passwords are less of a worry. I am more interested in securing the password that is already in place and keeping the script as small and as light as possible.