Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have wrote a password validation method which check existence of minimum 8 characters in password along with minimum 1 uppercase, 1 lowercase, 1 numeric and 1 symbolic character in it. if password is valid then it return a string "Good Password" else return "Week Password". and its working very fine.

Now when i get this string and do following action of code on password text box
C#
private void txtPassword_KeyUp(object sender, KeyEventArgs e)
        {
            string password = txtPassword.Text;
            lblValidation.ForeColor = Color.Red;

            string passValidation = ValidatePassword(password);

            if (passValidation == "Good Password")
            {
                lblValidation.ForeColor = Color.Green;
                lblValidation.Text = passValidation;
                lblPasswordInstructions.Visible = false;
            }
            else
            {
                lblValidation.Text = passValidation;
                lblPasswordInstructions.Visible = true;
            }
        }

lblValidation didn't change its colour from red to green. also lblPasswordInstructions didn't hide itself just "Good Password" and "Week Password" are shown with red in colour.
Posted
Comments
[no name] 30-Jun-13 23:00pm    
Well the first thing is that you need to debug ValidatePassword and see what it is doing. You have not given us enough information to tell you anything other than ValidatePassword is not returning "Good Password" for whatever your input is. And the word you want is "Weak" not "Week".
Hitesh Rohilla 30-Jun-13 23:45pm    
that doesn't matter as ValidatePassword working correctly and its returned string is shown on lblValidation. only change in text color of lblValidation and showing/hiding of lblPasswordInstructions is not working correctly which are coded in txtPassword_KeyUp event only. and thanks for correction of that word.

1 solution

Of course you can change the color of a label as many time as you want. Your problem is in pure logic. Run it under the debugger, put a breakpoint on the color property assignment with the color you fail to see and you will probably see that this value is never assigned to the property.

No wonder — comparison of anything with hard-coded immediate constant like your "Good password" hardly can be called a reliable approach to programming. :-)

—SA
 
Share this answer
 
Comments
Hitesh Rohilla 30-Jun-13 23:45pm    
Thanks for your reply Sergey. i don't know what happened previously but now its working fine. i think its about visual studio malfunctioning. just one restart of project make this working correctly.
Sergey Alexandrovich Kryukov 30-Jun-13 23:52pm    
I bet you just had incorrect observation.
—SA
Hitesh Rohilla 30-Jun-13 23:59pm    
No its true i didn't change anything in code and it just working fine now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900