Using Password Without User Name

Hello friends…

           On my project I want to check the password that username wasn't present in the registration form.

That means if username: "vijay" means this "vijay" was not used in password. if the user used this error need to be occur.

                            eg:


                                      username :vijay


                                      password :vijay05 or vijay05 or 05vijay05





                                error: don't use username in the password.


   


             


        This is the result i need.Is their any logic help me out.

In your model:




    public function checkPassword($attribute, $params)

    {

        if (strpos($this->password, $this->username) !== false)

        {

            $this->addError('password', 'Your password must not contain your user name.');

        }

    }



Then add the following rule:




    array('password', 'checkPassword'),



hi Keith…

thanks for your reply…

i used this in my model bt it not working…

i using like this


public function checkPassword($password, $username)

    {

        if (strpos($this->password, $this->username) !== false)

        {

            $this->addError('password', 'Your password must not contain your user name.');

        }

    }



and am using md5 in the password field, is that issue for not checking properly?

it never shows error bt its not working keith…

It will only work while the password is plain text. If you’re going to perform password validation, you need to do so before you hash it.

I changed whatever u said now i got this error keith.


strpos() [<a href='function.strpos'>function.strpos</a>]: Empty delimiter