[PHP]
/*
Consider the following scenario:
1 times password error, reminder to re-login
2 times wrong, out of verification code
5 times error, verification code becomes complicated
10 times wrong, locked account
General ideas:
When the user name/password mismatch is determined {
if (wrong) {
Count +1
}
if (number ==1) {
} else if (number ==2) {
} else {
}....
....
This is obviously unreasonable.
}
Determine whether the user name/password is correct or not, this belongs to the login class
Landing success/failure, reward/punishment is a bonus category.
*/
Interface Observer {
function Update ($obj);
}
Interface Post {
function Attach ($key, $obj);
function detach ($key);
function Noticefy ();
}
Class User implements Post {
public $state = null;
Public $lastlogin = 0;
Protected $observers = Array ();
Public function Attach ($key, $obj) {
$this->observers[$key] = $obj;
}
Public function Detach ($key) {
unset ($this->observers[$key]);
}
Public Function noticefy () {
foreach ($this->observers as $obj) {
$obj->update ($this);
}
}
Public Function Login () {
$this->state = rand (0,1); Returns 0 on behalf of username/password error; Return 1, Login successful
Notifications are listening to all my objects
$this->noticefy ();
return $this->state;
}
}
Class Log implements observer{
Public Function Update ($obj) {
The log analyzes
echo $obj->state? ' Add 1 points, record ': ' Wrong 1 times, record and analyze ';
Echo '
';
}
}
Class Biz implements observer{
Public Function Update ($obj) {
Echo (Time ()-$obj->lastlogin) > 1000? ' Long time no come ': ' Quality customer ';
}
}
$user = new User ();
$log = new log ();
$biz = new Biz ();
$user->attach (' log ', $log);
$user->attach (' biz ', $biz);
It's ======client's end, =====//.
for ($i =1; $i <10; $i + +) {
$user->login ();
Echo ' ';
}
/*
Consider the following scenario:
1 times password error, reminder to re-login
2 times wrong, out of verification code
5 times error, verification code becomes complicated
10 times wrong, locked account
General ideas:
When the user name/password mismatch is determined {
if (wrong) {
Count +1
}
if (number ==1) {
} else if (number ==2) {
} else {
}....
....
This is obviously unreasonable.
}
Determine whether the user name/password is correct or not, this belongs to the login class
Landing success/failure, reward/punishment is a bonus category.
*/
Interface Observer {
function Update ($obj);
}
Interface Post {
function Attach ($key, $obj);
function detach ($key);
function Noticefy ();
}
Class User implements Post {
public $state = null;
Public $lastlogin = 0;
Protected $observers = Array ();
Public function Attach ($key, $obj) {
$this->observers[$key] = $obj;
}
Public function Detach ($key) {
unset ($this->observers[$key]);
}
Public Function noticefy () {
foreach ($this->observers as $obj) {
$obj->update ($this);
}
}
Public Function Login () {
$this->state = rand (0,1); Returns 0 on behalf of username/password error; Return 1, Login successful
Notifications are listening to all my objects
$this->noticefy ();
return $this->state;
}
}
Class Log implements observer{
Public Function Update ($obj) {
The log analyzes
echo $obj->state? ' Add 1 points, record ': ' Wrong 1 times, record and analyze ';
Echo '
';
}
}
Class Biz implements observer{
Public Function Update ($obj) {
Echo (Time ()-$obj->lastlogin) > 1000? ' Long time no come ': ' Quality customer ';
}
}
$user = new User ();
$log = new log ();
$biz = new Biz ();
$user->attach (' log ', $log);
$user->attach (' biz ', $biz);
It's ======client's end, =====//.
for ($i =1; $i <10; $i + +) {
$user->login ();
Echo '
';
}
http://www.bkjia.com/PHPjc/477316.html www.bkjia.com true http://www.bkjia.com/PHPjc/477316.html techarticle [PHP]/* Consider the following scenario: 1 password errors, reminders to re-login 2 times the wrong, out of the verification code 5 times the wrong, the verification code becomes complex 10 times wrong, locked the account general idea: When the user name/password does not match ...