You must Sign In to post a response.

login form in C#

I am creating a windows login form in visual C# with two textboxes one for accepting the username and other for accepting the password and one button control. I am setting the username as "Rajan" and password as "Admin".

I need to implement the following conditions in my login form.

i)While typing the username, i want the first character alone to get changed into CAPS automatically.
ii)If either the username or the password is wrong then i should get a message box "Invalid login". Else i should get the message "Login Successful".
iii)The application has 2 forms - Form2 and Form3. If the user enters with the "Admin" password then the Form2 should be displayed. Else if the user enters with the password "Guest" then the Form 3 should be displayed. How to do the validation in code.

Can anybody provide the full code?


Comments

Author: pradipta27 Jul 2008 Member Level: Gold   Points : 6

Private Sub txtLogin_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLogin.TextChanged
Dim str As String = txtLogin.Text
If (str.Length > 0) Then
txtLogin.Text = str.Substring(0, 1).ToUpper() & str.Substring(1, str.Length - 1).ToLower
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtLogin.Text.Equals("Rajan") AndAlso (txtPassword.Text.Equals("Admin") Or txtPassword.Text.Equals("Guest")) Then
MessageBox.Show("Login Successful")
If (txtPassword.Text.Equals("Admin")) Then
Form2.Show()
Else
Form3.Show()
End If
Else
MessageBox.Show("Invalid Login")
End If
End Sub

Author: Raghuramakarthikeyan28 Jul 2008 Member Level: Gold   Points : 6

using System.Windows.Forms;
Private Sub txtLogin_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
{
if(textbox1.text!="" && textbox2.text!="")
{
textbox1.Text = str.Substring(0, 1).ToUpper();
if(textbox1.text=="Rajan")
{
if(textbox2.text=="Admin")
{
Form2.Show();
}
else if(textbox2.text=="Guest")
{
Form3.Show();
}
else
{
MessageBox.Show("Invalid Login")
}
}
else
{
MessageBox.Show("Invalid Login")
}
}
}

this will help you