Created
February 26, 2011 10:46
-
-
Save xqus/845100 to your computer and use it in GitHub Desktop.
Grunnleggende kryptografi for webutviklere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Last inn biblioteket og sett parametre. | |
Se: https://github.com/xqus/phpSec/wiki/Getting-started */ | |
require_once 'phpsec.class.php'; | |
phpsec::$_datadir = '/var/www/phpSec/data'; | |
phpsec::$_logdir = '/var/www/phpSec/logs'; | |
phpsec::init(); | |
/* Først krypterer vi. */ | |
$data = 'Noe kjempe hemmelig!'; | |
$encrypted = phpsecCrypt::encrypt($data, 'my secret key'); | |
/* Så kan vi dekryptere. */ | |
echo phpsecCrypt::decrypt($encrypted, 'my secret key'); // Vil returnere 'Noe kjempe hemmelig!'. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Last inn biblioteket og sett parametre. | |
Se: https://github.com/xqus/phpSec/wiki/Getting-started */ | |
require_once 'phpsec.class.php'; | |
phpsec::$_datadir = '/var/www/phpSec/data'; | |
phpsec::$_logdir = '/var/www/phpSec/logs'; | |
phpsec::init(); | |
/* Bruker vil ha somePassword til passord. Lag en sjekksum. */ | |
$hash = phpsec::pwHash('somePassword'); | |
/* Oppdater brukertabellen med den nye sjekksumen. */ | |
/* ------------ Kontrollere passord ------------------------- */ | |
/* For å kontrollere et passord når en bruker forsøker å logge inn | |
benyttes phpsec::pwCheck(); */ | |
/* Hent $hash fra database. */ | |
$hash = $fromDb['userPw']; | |
/* Kontroller passordet brukeren skrev inn med det som ligger i databasen. */ | |
if(phpsec::pwCheck($_POST['password'], $hash)) { | |
/* Gyldig passord. */ | |
} else { | |
/* Feil passord. */ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo hash('sha256', 'my password'); | |
/* Produserer: bb14292d91c6d0920a5536bb41f3a50f66351b7b9d94c804dfce8a96ca1051f2 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment