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
<?php
// this class featured hashing capabilities
class MessageDigester extends CComponent {
const ALGORITM_MD5 = 0;
const ALGORITM_SHA1 = 1;
public $salt = 'ibad1314';
public function init(){
// overriding this method is a mandatory
}
// do the digesting
public function digest($_message, $_algorithm = self::ALGORITM_MD5) {
switch ($_algorithm){
case self::ALGORITM_MD5:
return $this->md5($_message);
case self::ALGORITM_SHA1:
return $this->sha1($_message);
default :
return (NULL);
}
}
// an md5 digesting
public function md5($_message) {
return(md5($_message . $this->salt));
}
// a sha1 digesting
public function sha1($_message) {
return(sha1($_message . $this->salt));
}
}
?>