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;
}
}
}
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveUser {
private $userID;
private $allowDelete=FALSE;
public function __construct( $userID )
{
$this->setUserID($userID);
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setUserID( $userID )
{
$this->userID = $userID;
}
private function handle()
{
//$this->checkIfUserHasProjects();
}
}
@@ -0,0 +1,72 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 14:10
*/
class UserCreation {
private $user;
private $passWordRecipe;
private $password;
private $saltedPassword;
private $salt;
public function __construct( $user )
{
$this->setUser( $user );
$this->handle();
}
public function getUser()
{
return $this->user;
}
public function getPassword()
{
return $this->password;
}
private function setUser( $user )
{
$this->user = $user;
}
private function handle()
{
$this->passWordRecipe = new PasswordRecipe();
$this->setPassword();
$this->setSalt();
$this->setSaltedPassword();
$this->enrichUser();
}
private function setPassword()
{
$this->password = $this->passWordRecipe->getPassword();
}
private function setSalt()
{
$this->salt = $this->passWordRecipe->getSalt();
}
private function setSaltedPassword()
{
$this->saltedPassword = $this->passWordRecipe->getSaltedPassword();
}
private function enrichUser()
{
$this->user['password'] = $this->saltedPassword;
$this->user['salt'] = $this->salt;
}
}
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/07/16
* Time: 13:35
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class CustomerValidation extends BaseValidation {
protected $validationFields = [
'name' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'name'
],
'contactperson' => [
'validations' => 'required|alphaNumericSpaces',
'fieldname' => 'contactperson'
],
'email' => [
'validations' => 'email',
'fieldname' => 'email'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}