Added passwordfield
This commit is contained in:
parent
4238c210a4
commit
778a2996df
1 changed files with 69 additions and 0 deletions
69
src/CoreFields/PasswordField.php
Normal file
69
src/CoreFields/PasswordField.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||
* @file
|
||||
* @package ExtraFields
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PhangoApp\PhaModels\CoreFields;
|
||||
use PhangoApp\PhaUtils\Utils;
|
||||
|
||||
class PasswordField extends CharField {
|
||||
|
||||
|
||||
function __construct($size=255)
|
||||
{
|
||||
|
||||
$this->size=$size;
|
||||
$this->form='PasswordForm';
|
||||
|
||||
}
|
||||
|
||||
public function check($value)
|
||||
{
|
||||
|
||||
$value=trim($value);
|
||||
|
||||
if($value=='')
|
||||
{
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
$token_pass=Utils::generate_random_password();
|
||||
|
||||
$hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value);
|
||||
|
||||
return $hash_password;
|
||||
|
||||
}
|
||||
|
||||
//I load the password with the username and check here.
|
||||
|
||||
static public function check_password($value, $hash_password_check)
|
||||
{
|
||||
|
||||
//If pass have _ check if work fine...
|
||||
|
||||
$token_pass=preg_replace('/(.*)[_].*/', '$1', $hash_password_check);
|
||||
|
||||
$hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value);
|
||||
|
||||
if($hash_password==$hash_password_check)
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue