blob: c5319500478eb357fd993b4d5b220d37b9d548f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php
use Base\User as BaseUser;
/**
* Skeleton subclass for representing a row from the 'user' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class User extends BaseUser
{
/* (non-PHPdoc)
* @see \Base\User::setPassword()
*/
public function setPassword($v)
{
if(parent::getSalt() == null)
{
parent::setSalt(md5(uniqid(rand(), true), 0, 20));
}
return parent::setPassword(self::createHash($v));
}
/**
* A function to check a password against a given string.
*
* @param string $v The password to check.
* @return boolean
* If password equals $v
*/
public function checkPassword($v)
{
if(parent::getSalt() == null)
{
return false;
}
return self::createHash($v) == parent::getPassword();
}
/**
* Create a password hash with sha-1
*
* @param string $v The password to hash
* @return string
* The hashed and salted password
*/
private function createHash($v)
{
return sha1(parent::getSalt() . $v);
}
}
|