I'm making a bigger site for the first time so security really matters, unlike for my really-bad boards with maybe 10 users. So I wanted to ask if the way I'm doing it is secure enough for a semi-big application where money is involved.
The site is written in PHP, database is MySql. This is the current login.
First off, I have a 128 sign long salt and session key saved in the local config.
On every site that interacts with sessions (e.g. the user control panel) I have this snippet at the start of the code:
session_start();
if (empty($_SESSION)) {
session_regenerate_id(true);
}
After that I connect to the database, escape all the strings and read out the data.
After that, I compare the two passwords which got hashed with SHA-512 and the salt from before:
public static function hashValue($str) {
for ($x = 0; $x < 10000; $x++) {
$str = hash('sha512', $str . self::$salt);
}
return $str;
}
If everything is correct, $_SESSION[$sessionkey]
gets set with the user ID from the database (altough the long session key shouldn't be neccessary because the client can't change the $_SESSION
vars locally anyway, IIRC. Right?)
If the site is secured (as in, users not logged in don't have access) this code is called to redirect them back to the index if they aren't logged in:
if (!isset($_SESSION[$sessionkey])) {
header("Location: ?view=default");
exit;
}
Is this application secure? I've read somewhere that its better to have a randomly generated salt for each user, saved in the database. Is that really neccessary, considering it only really prevents brute forcing a bit better, which shouldnt be a problem with a captcha anyway?
Location
header should properly take a full URL, including protocol and domain name. Most browsers understand it without, but this is not technically compliant with the standard.