summaryrefslogtreecommitdiffstats
path: root/generated-classes/User.php
blob: b8ad0000d4f6e93c448e9e4f322c3be25c505c98 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?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();
	}
	
	/* (non-PHPdoc)
	 * @see \Base\User::getUsername()
	 */
	public function getUsername()
	{
		return htmlentities(parent::getUsername());
	}
	
	/* (non-PHPdoc)
	 * @see \Base\User::getPassword()
	 */
	public function getPassword()
	{
		return htmlentities(parent::getPassword());
	}
	
	/* (non-PHPdoc)
	 * @see \Base\User::getSalt()
	 */
	public function getSalt()
	{
		return htmlentities(parent::getSalt());
	}
	
	/**
	 * 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);
	}
}