Home > Error Message > Login Error Message Best Practices

Login Error Message Best Practices

Contents

Total 2 comments #3637 report it 0 0 Francis.TM at 2011/04/25 09:15pm CBaseUserIdentity::getName() must be defined for CWebUser::login As the title said, If an class which extends from CBaseUserIdentity and it more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed Do students wear muggle clothing while not in classes at Hogwarts (like they do in the films)? CComponent evaluateExpression() Evaluates a PHP expression or callback under the context of this component. navigate here

The default implementation simply returns empty string. Not the answer you're looking for? Not the answer you're looking for? CComponent attachEventHandler() Attaches an event handler to an event.

Login Error Message Best Practices

public function authenticate($attribute,$params) { if(!$this->hasErrors()) { $this->_identity=new UserIdentity($this->username,$this->password); if($this->_identity->authenticate() == 1) $this->addError('username','Invalid username.'); else if($this->_identity->authenticate() == 2) $this->addError('password','Incorrect password.'); // Your Custom Error :) else if($this->_identity->authenticate() == 3) $this->addError('username', 'Username is But beyond the tutorial, one of the common things that developers seem to want to do after customizing the login authentication of CUserIdentity, is to customize the error messages that are Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account. (LogOut/Change) You are more hot questions question feed lang-php about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation

Partial source code of class CBaseUserIdentity: abstract class CBaseUserIdentity extends CComponent implements IUserIdentity {         const ERROR_NONE=0;         const ERROR_USERNAME_INVALID=1;         const ERROR_PASSWORD_INVALID=2;         const ERROR_UNKNOWN_IDENTITY=100; Custom Error Message UserIdentity is Can a PCIe bus exist on its own? Was there no tax before 1913 in the United States? However when you do a login and say enter the wrong user name (or really an invalid/unregistered one) you get a generic error code that doesn't really clarify what the issue

Derived classes should override this method, or an exception will be thrown. Login Error Message Examples The default implementation simply returns username. The point of the LoginForm authenticate function then is to determine if there are any errors. What did John Templeton mean when he said that the four most dangerous words in investing are: ‘this time it’s different'?

php yii share|improve this question asked May 30 '13 at 18:07 Ajay Kumar 3618 Is the user actually logging in somewhere? –Ivo Renkema May 30 '13 at 18:23 These reference to which field to show the error under. It's because we are only passing a true or false condition. That's it for the tutorial, I hope you learned a lot in understanding how to follow the logical flow of code assignments and debugging the functions, variables and classes in this

Login Error Message Examples

CBaseUserIdentity setState() Sets the named state with a given value. CComponent hasProperty() Determines whether a property is defined. Login Error Message Best Practices I also hope this helps you put to good use how to modify your own custom errors into the login authentication process. Error Message Examples Text So use 3 Within the login form model you can add errors to the form: if($this->_identity->errorCode===UserIdentity::ERROR_EMAIL_INACTIVE) { $this->addError('username','Account is not activated yet!'); } Extension: AdvancedEmailValidator Extension: Config Extension: Mutex Yii Cookbook:

So logically you will run a check of if your user is active or not before allowing them to log in. check over here CComponent __set() Sets value of a component property. Derived classes should implement authenticate with the actual authentication scheme (e.g. Is HTTPS used on your site?

more hot questions question feed lang-php about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation How to use a variable for a line of code of an script? Now we could show the view code of the LoginForm but understanding MVC architecture, the error code settings will not be defined in the view. his comment is here How is True < 2 implemented?

Conditional iterative arrow in Latex Tikz What is really curved, spacetime, or simply the coordinate lines? CComponent detachEventHandler() Detaches an existing event handler. CBaseUserIdentity name string Returns the display name for the identity.

CComponent enableBehavior() Enables an attached behavior.

CUserIdentity isAuthenticated boolean Returns a value indicating whether the identity is authenticated. There are actually several key things that need to be adjusted in order to make a custom error message for the login portal. That's simple, now that we have the framework in place to customize and evaluate errors, we just need to define our own error. more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed

They could be set in the controller (which would be sitecontroller) but because an error value is just that, a value (thus a property of a class), there's a good chance Also when i print Yii::app()->user->name, it shows the username. How to send the user to the login page Hot Network Questions How can ransomware know file types? http://thetechevent.com/error-message/website-down-for-maintenance-message.html Modified source code of public method authenticate() in class LoginForm: public function authenticate($attribute,$params) {     if(!$this->hasErrors())     {         $this->_identity=new UserIdentity($this->username,$this->password);         $this->_identity->authenticate();         if($this->_identity->errorCode==UserIdentity::ERROR_USERNAME_INVALID)             $this->addError('password','Incorrect user

share|improve this answer answered Jan 7 '13 at 12:10 topher 9,34822353 thanx @topher .. –Rohitashv Singhal Jan 7 '13 at 13:07 add a comment| up vote 0 down vote CComponent disableBehavior() Disables an attached behavior. CComponent getEventHandlers() Returns the list of attached event handlers for an event. Not the answer you're looking for?

This method is required by IUserIdentity. CBaseUserIdentity errorMessage string the authentication error message. database). * @return boolean whether authentication succeeds. */ public function authenticate() { $users=array( // username => password 'demo'=>'demo', 'admin'=>'admin', ); if(!isset($users[$this->username])) $this->errorCode=self::ERROR_USERNAME_INVALID; else if($users[$this->username]!==$this->password) $this->errorCode=self::ERROR_PASSWORD_INVALID; else $this->errorCode=self::ERROR_NONE; return !$this->errorCode; } } CBaseUserIdentity hasEvent() Determines whether an event is defined.

Safely adding insecure devices to my home network Do students wear muggle clothing while not in classes at Hogwarts (like they do in the films)?