Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi! i'm developing an application where a user has to log in to work with that app and its working fine but the only problem with is that to enter the password i have used a text box instead of a masked text box that is coz i'm unable to get the values from the masked text box i mean i have to retrieve the value that a person has typed in the masked text box and compare it with the database but i don't know how to get that value and there is one more constraint that is before all this i need to check if the masked text box is empty if so i have to display a message telling the user that he/she have entered an empty password
so any thoughts on this.
thank you in advance.
how ever the code i used is here
private void btnLogin_Click(object sender, EventArgs e)
     {
         int f = 1;
         if (txtboxLoginName.Text == "")
         {
             MessageBox.Show("enter user name");
         }
         else
         {
          string Qstr = null;
          Qstr = "select * from password";
         dsBind = dm.GetDataSet(Qstr);
         int j;
         for (j = 0; j < dsBind.Tables[0].Rows.Count; j++)
          {
         if (txtBoxLoginName.Text.Equals(dsBind.Tables[0].Rows[j]["name"]))
           {
      if (txtBoxPassword.Text.Equals(dsBind.Tables[0].Rows[j]["password"]))
                     {
                         f = 0;
                         break;
                     }
                 }
             }
             if(f == 0)
             {
               MessageBox.Show("you are logged in");
             }
             else
             {
               MessageBox.Show("password and user name  did not match");
             }
          }
      }
Posted
Updated 13-Apr-12 23:46pm
v2
Comments
Bala Selvanayagam 14-Apr-12 5:55am    
Are you saying that you have used "masked" text box for the password field and unable to retrive the value typed at run time ?

I would have throught the Text property of the masked text box will do ?
shrav007 14-Apr-12 5:59am    
hmmm ya kind of similar problem and by default the value will be null so i need to compare the entered value with it and then proceed

guess i figured this out i used if(maskedtextbox1.MaskFull) and its working fine for now
 
Share this answer
 
First off, don't use a masked text box unless you are forcing users to have formatted passwords such as AAAA-BBBB - use a standard textbox and set the UseSystemPasswordChar[^] property to mask it.

Second, checking for an empty password is simple:
.NET up to V3.5
C#
if (string.IsNullOrEmpty(txtBoxPassword.Text))
   {
   // Report error
   }

.NET from V4.0
C#
if (string.IsNullOrWhiteSpace(txtBoxPassword.Text))
   {
   // Report error
   }


Thirdly, don't report a separate error: Use a generic "the username and password were not recognised" - if you report of specific password problems it tells hackers when they have a valid username.

Fourthly, ever store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
Share this answer
 
Comments
VJ Reddy 14-Apr-12 6:04am    
Nice answer and advice. 5!
shrav007 14-Apr-12 6:05am    
it is for an user application i mean a lame user so he will need assistance to use that application
and ya i actually wanna restrict an user to a specified format of choosing their password so i have to use masked text box only
OriginalGriff 14-Apr-12 6:37am    
The problem with that is that it can reduce security!
Seriously - it makes passwords harder for the user to remember, which means they get written down on a post it and stuck to the side of the monitor...
If you want to assist him, then give him a suggestion for the password - along the lines of what AOL (ack, spit) used to do: "Word in native language" "Special character" "Word in native language" - like "Cereal$Banana" or "Scarlet-Omen"

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