]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Core/AbstractPassword.php
Remove 'svn' lines
[galette.git] / galette / lib / Galette / Core / AbstractPassword.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Abstract password for galette. The original code was found
7 * in includes/functions.inc.php
8 *
9 * PHP version 5
10 *
11 * Copyright © 2003-2016 The Galette Team
12 *
13 * This file is part of Galette (http://galette.tuxfamily.org).
14 *
15 * Galette is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * Galette is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
27 *
28 * @category Core
29 * @package Galette
30 *
31 * @author Frédéric Jaqcuot <unknown@unknow.com>
32 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
33 * @author Johan Cwiklinski <johan@x-tnd.be>
34 * @copyright 2003-2016 The Galette Team
35 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
36 * @link http://galette.tuxfamily.org
37 * @since Available since 0.9dev - 2016-11-08
38 */
39
40 namespace Galette\Core;
41
42 use Analog\Analog;
43 use Laminas\Db\Adapter\Exception as AdapterException;
44 use Galette\Entity\Adherent;
45
46 /**
47 * Abstract password
48 *
49 * @category Core
50 * @name AbstractPassword
51 * @package Galette
52 * @author Frédéric Jaqcuot <unknown@unknow.com>
53 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
54 * @author Johan Cwiklinski <johan@x-tnd.be>
55 * @copyright 2009-2016 The Galette Team
56 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
57 * @link http://galette.tuxfamily.org
58 * @since Available since 0.9dev - 2016-11-08
59 */
60
61 abstract class AbstractPassword
62 {
63 /** Default password size */
64 const DEFAULT_SIZE = 8;
65
66 protected $chars = 'abcdefghjkmnpqrstuvwxyz0123456789';
67 protected $hash = null;
68 protected $new_password;
69
70 /**
71 * Generates a random passord based on default salt
72 *
73 * @param int $size Password size (optionnal)
74 *
75 * @return string random password
76 */
77 public function makeRandomPassword($size = null)
78 {
79 if (
80 $size === null
81 || trim($size) == ''
82 || !is_int($size)
83 ) {
84 $size = self::DEFAULT_SIZE;
85 }
86 $pass = '';
87 $i = 0;
88 while ($i <= $size - 1) {
89 $num = mt_rand(0, 32) % 33;
90 $pass .= substr($this->chars, $num, 1);
91 $i++;
92 }
93 return $pass;
94 }
95
96 /**
97 * Generates a new password for specified member
98 *
99 * @param mixed $arg Any argument required
100 *
101 * @return boolean
102 */
103 abstract public function generateNewPassword($arg);
104
105 /**
106 * Remove expired passwords queries (older than 24 hours)
107 *
108 * @return boolean
109 */
110 abstract protected function cleanExpired();
111
112 /**
113 * Retrieve new pasword for sending it to the user
114 *
115 * @return string the new password
116 */
117 public function getNewPassword()
118 {
119 return $this->new_password;
120 }
121
122 /**
123 * Retrieve new hash
124 *
125 * @return string hash
126 */
127 public function getHash()
128 {
129 return $this->hash;
130 }
131
132 /**
133 * Set password
134 *
135 * @param string $password Password
136 *
137 * @return void
138 */
139 protected function setPassword($password)
140 {
141 $this->new_password = $password;
142 }
143
144 /**
145 * Set hash
146 *
147 * @param string $hash Hash
148 *
149 * @return void
150 */
151 protected function setHash($hash)
152 {
153 $this->hash = $hash;
154 }
155 }