Skip to content

Commit

Permalink
[authentication] Hash password
Browse files Browse the repository at this point in the history
  • Loading branch information
LaercioSantana committed Jul 17, 2016
1 parent b448727 commit 59438cb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions application/controllers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require APPPATH.'/libraries/Jsv4/Validator.php';
require APPPATH.'/libraries/Jsv4/ValidationException.php';
include( APPPATH.'controllers/Authentication.php' );
include(APPPATH."config/config.php");

/**
* @apiDefine tokenParam
Expand Down Expand Up @@ -80,7 +81,7 @@ public function create(){
if($validator->valid){
$this->loadModel();

$input = json_decode($this->input->raw_input_stream);
$input = $this->userFromJson($this->input->raw_input_stream);
$result = $this->user_model->insert($input);

if(!$result){//check conflict
Expand Down Expand Up @@ -129,7 +130,7 @@ public function getToken(){
$validator = $this->validateJson($this->input->raw_input_stream, APPPATH.'/controllers/Schemas/UsersLogin.json');
if($validator->valid){
$this->loadModel();
$input = json_decode($this->input->raw_input_stream);
$input = userFromJson($this->input->raw_input_stream);

$user = $this->user_model->get($input);
unset($input->password);
Expand Down Expand Up @@ -196,4 +197,16 @@ function validateJson($json, $schemaPath){

return $validator;
}
public function userFromJson($json){
$user = json_decode($this->input->raw_input_stream);
$user->password = User::hash($user->password);
return $user;
}
private static function SALT_USER_PASSWORD(){
global $BusTrackerConfig;
return $BusTrackerConfig["SALT_USER_PASSWORD"];
}
private static function hash($value){
return hash('sha512', User::SALT_USER_PASSWORD().$value);
}
}

0 comments on commit 59438cb

Please sign in to comment.