Users ready

This commit is contained in:
2017-12-29 14:44:18 +01:00
parent f73e20d0bc
commit cb0567d3f3
32 changed files with 1298 additions and 201 deletions
@@ -8,8 +8,8 @@
class PasswordRecipe {
private $nakedPassword = false;
private $salt = false;
private $password = FALSE;
private $salt = FALSE;
private $saltedPassword;
public function __construct()
@@ -17,9 +17,24 @@ class PasswordRecipe {
$this->handle();
}
public function setNakedPassword( $nakedPassword )
public function getPassword()
{
$this->nakedPassword = $nakedPassword;
return $this->password;
}
public function getSalt()
{
return $this->salt;
}
public function getSaltedPassword()
{
return $this->saltedPassword;
}
public function setPassword( $password )
{
$this->password = $password;
}
public function setSalt( $salt )
@@ -29,52 +44,55 @@ class PasswordRecipe {
private function handle()
{
$this->checkNakedPassword();
$this->checkPassword();
$this->checkSalt();
$this->setSaltedPassword();
}
private function checkNakedPassword()
private function checkPassword()
{
if( ! $this->nakedPassword ) $this->createNakedPassword();
if ( ! $this->password ) $this->createPassword();
if( strlen($this->nakedPassword) < 6 ) return;
if ( strlen( $this->password ) < 6 ) return;
}
private function checkSalt()
{
if( ! $this->salt ) $this->createSalt();
if ( ! $this->salt ) $this->createSalt();
}
private function createNakedPassword()
private function createPassword()
{
$pass = $this->getRandomString(8);
$pass = $this->getRandomString( 8 );
$this->nakedPassword = $pass;
$this->password = $pass;
}
private function createSalt()
{
$salt = $this->getRandomString(8);
$salt = $this->getRandomString( 18 );
$this->salt = $salt;
$this->salt = sha1($salt);
}
private function setSaltedPassword()
{
$this->saltedPassword = sha1($this->)
$this->saltedPassword = sha1( sha1( $this->password ) . $this->salt );
}
private function getRandomString( $length=8 )
private function getRandomString( $length = 8 )
{
$rand = '';
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $length; $i++) {
$n = rand(0, $alphaLength);
$rand.= $alphabet[$n];
$alphaLength = strlen( $alphabet ) - 1; //put the length -1 in cache
for ( $i = 0; $i < $length; $i ++ )
{
$n = rand( 0, $alphaLength );
$rand .= $alphabet[ $n ];
}
return $rand;
}
}
}