Using functions to obfuscate the hash generation does not increase security. This is security by obscurity. The algorithm used to hash the data needs to be secure by itself.
I would not suggest to use other data as salt. For example if you use the username, you won't be able to change the values without rehashing the password.
I would use a dedicated salt value stored in the same database table.
Why? Because a lot of users use the same login credentials on different web services. And in case another service also uses the username as salt, the resulting hashed password might be the same!
Also an attacker may prepare a rainbow table with prehashed passwords using the username and other known data as salt. Using random data would easily prevent this with little programming effort.
Model de stocare criptată
SSL/SSH protejează traversarea datelor de la client la server, însă SSL/SSH nu protejează datele stocate în baza de date. SSL este un protocol de tranzit.
Odată ce atacatorul capătă acces la baza de date direct (evitând serverul web), informația stocată poate fi expusă sau abuzată, dacă ea nu este protejată de însăși baza de date. Criptarea datelor este o bună masură pentru a diminua acest risc, însă prea puține baze de date oferă acest tip de criptare.
Cea mai ușoară cale de a rezolva problema este de a crea propriul pachet de criptare, și apoi folosirea lui cu scripturile PHP. PHP vă poate ajuta în aceasta prin intermediul câtorva extensii, cum ar fi Mcrypt și Mhash, care acoperă o varietate largă de algoritmi de criptare. Scriptul criptează datele înainte de a fi inserate în baza de date, și le decriptează la extragerea acestora. Verificați documentația de rigoare pentru a studia mai multe despre modalitățile de operare ale criptării.
În cazul datelor care trebuie să fie confidențiale, a căror expunere nu este necesară în nici un context, procedeul hashing poate fi luat în considerare. Cel mai cunoscut exemplu este stocarea hash-ului MD5 al unei parole în baza de date, în loc de stocarea parolei înseși. Vedeți de asemenea și funcțiile crypt() și md5().
Example #1 Utilizarea hash-ului pentru parole
<?php
// stocăm hash-ul parolei --> md5($password)
$query = sprintf("INSERT INTO users(name,pwd) VALUES('%s','%s');",
pg_escape_string($username), md5($password));
$result = pg_query($connection, $query);
// query - verificare dacă utilizatorul a introdus parola corectă
$query = sprintf("SELECT 1 FROM users WHERE name='%s' AND pwd='%s';",
pg_escape_string($username), md5($password));
$result = pg_query($connection, $query);
if (pg_num_rows($result) > 0) {
echo 'Bine ai venit, $username!';
} else {
echo 'Autentificarea a eșuat pentru $username.';
}
?>
In addition to roysimkes at hotmail dot com:
If your passwords are so secret that they're worth a year's hacking/cracking/etc, you might want to consider 'password renewal', much like Windows' option. Tell your users to renew their passwords every x days/weeks/months to make it extra hard on those already-sweating malicious visitors.
A better way to hash would be to use a separate salt for each user. Changing the salt upon each password update will ensure the hashes do not become stale.
I think the best way to have a salt is not to randomly generate one or store a fixed one. Often more than just a password is saved, so use the extra data. Use things like the username, signup date, user ID, anything which is saved in the same table. That way you save on space used by not storing the salt for each user.
Although your method can always be broken if the hacker gets access to your database AND your file, you can make it more difficult. Use different user data depending on random things, the code doesn't need to make sense, just produce the same result each time. For example:
if ((asc(username character 5) > asc(username character 2))
{
if (month the account created > 6)
salt = ddmmyyyy of account created date
else
salt = yyyyddmm of account created date
}
else
{
if (day of account created > 15)
salt = user id * asc(username character 3)
else
salt = user id + asc(username character 1) + asc(username character 4)
}
This wont prevent them from reading passwords when they have both database and file access, but it will confuse them and slow them up without much more processing power required to create a random salt
