[Php]/* Consider the following scenarios: one wrong password, two wrong login attempts, five wrong verification codes, and 10 wrong verification codes. the general idea of locking the account is as follows: {if (error) {Times + 1} if (Times = 1) {} elseif (Times = 2) {} else... "/> <scripttype =" text/plain CR
[Php]
/*
Consider the following scenarios:
The password is incorrect once, prompting you to log on again
Two errors. the verification code is displayed.
Five errors make the verification code more complex
10 errors, locked account
General Idea:
{
If (error ){
Times + 1
}
If (Times = 1 ){
} Else if (Times = 2 ){
} Else {
}....
....
This is obviously unreasonable.
}
Determining whether the user name/password is correct is a login type
Logon success/failure, rewards/punishments are rewards and punishments.
*/
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 (); // if 0 is returned, the user name or password is incorrect. if 1 is returned, the logon is successful.
// The notification is listening to all my objects.
$ This-> noticefy ();
Return $ this-> state;
}
}
Class Log implements Observer {
Public function update ($ obj ){
// Log analysis
Echo $ obj-> state? 'Add 1 cent, record ': 'error 1 time, record and analytics ';
Echo'
';
}
}
Class Biz implements Observer {
Public function update ($ obj ){
Echo (time ()-$ obj-> lastlogin)> 1000? 'Long time has not come ': 'Excellent customer ';
}
}
$ User = new User ();
$ Log = new log ();
$ Biz = new Biz ();
$ User-> attach ('log', $ log );
$ User-> attach ('biz', $ biz );
// ======= Client-side events ====== //
For ($ I = 1; $ I <10; $ I ++ ){
$ User-> login ();
Echo'
';
}
/*
Consider the following scenarios:
The password is incorrect once, prompting you to log on again
Two errors. the verification code is displayed.
Five errors make the verification code more complex
10 errors, locked account
General Idea:
{
If (error ){
Times + 1
}
If (Times = 1 ){
} Else if (Times = 2 ){
} Else {
}....
....
This is obviously unreasonable.
}
Determining whether the user name/password is correct is a login type
Logon success/failure, rewards/punishments are rewards and punishments.
*/
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 (); // if 0 is returned, the user name or password is incorrect. if 1 is returned, the logon is successful.
// The notification is listening to all my objects.
$ This-> noticefy ();
Return $ this-> state;
}
}
Class Log implements Observer {
Public function update ($ obj ){
// Log analysis
Echo $ obj-> state? 'Add 1 cent, record ': 'error 1 time, record and analytics ';
Echo'
';
}
}
Class Biz implements Observer {
Public function update ($ obj ){
Echo (time ()-$ obj-> lastlogin)> 1000? 'Long time has not come ': 'Excellent customer ';
}
}
$ User = new User ();
$ Log = new log ();
$ Biz = new Biz ();
$ User-> attach ('log', $ log );
$ User-> attach ('biz', $ biz );
// ======= Client-side events ====== //
For ($ I = 1; $ I <10; $ I ++ ){
$ User-> login ();
Echo'
';
}