0% found this document useful (0 votes)
4 views

Program 20

The document is a C# code for a Windows Forms application that implements a login form. It includes validation for username, password, and confirm password fields, ensuring all are filled, that the password is alphanumeric and at least 6 characters long, and that the passwords match. If validation passes, a success message is displayed; otherwise, appropriate error messages are shown.

Uploaded by

krishgenshin4444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Program 20

The document is a C# code for a Windows Forms application that implements a login form. It includes validation for username, password, and confirm password fields, ensuring all are filled, that the password is alphanumeric and at least 6 characters long, and that the passwords match. If validation passes, a success message is displayed; otherwise, appropriate error messages are shown.

Uploaded by

krishgenshin4444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace LoginForm
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)


{
string username = txtUsername.Text;
string password = txtPassword.Text;
string confirmPassword = txtConfirmPassword.Text;
DateTime dob = dateTimePickerDOB.Value;
string rememberText = txtRemember.Text;

// Validation
if (string.IsNullOrWhiteSpace(username) ||
string.IsNullOrWhiteSpace(password) ||
string.IsNullOrWhiteSpace(confirmPassword))
{
MessageBox.Show("All fields are required!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

if (!Regex.IsMatch(password, "^(?=.*[a-zA-Z])(?=.*\\d).{6,}$"))
{
MessageBox.Show("Password must be alphanumeric and at least 6
characters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

if (password != confirmPassword)
{
MessageBox.Show("Passwords do not match!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

MessageBox.Show("Login Successful!", "Success", MessageBoxButtons.OK,


MessageBoxIcon.Information);
}
}
}

You might also like