Raga, mi servirebbe sapere che funzione posso usare per criptare una password ma poterla decriptare... l'md5 non mi interessa perchè non è reversibile.
Facendo una ricerca in questo forum, fra le altre cose, è saltata fuori questa:
Codice PHP:
<?php
function encrypt($string, $key) {
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
function decrypt($string, $key) {
$result = '';
$string = base64_decode($string);
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
echo encrypt("ciao gionnico","pippo"); // restituisce 0tnK35DW2dje3tjT2A==
echo "
";
echo decrypt("0tnK35DW2dje3tjT2A==","pippo"); // se passi la stringa alla funzione decrypt con la stessa chiave che hai usato per criptarla avrai la tua stringa di partenza
?>
Il problema è che già devo mettere in chiaro la chiave per ovvi motivi nel codice delle mie pagine, vorrei almeno evitare di piazzare nel codice l'implementazione stessa della funzione...
non ne esiste una già insita in PHP?