You must Sign In to post a response.
  • Category: Visual Studio

    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?
  • #270857
    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

  • #271598
    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


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.