SqlTable:
```sql
CREATE TABLE [dbo].[Registration] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NCHAR (10) NULL,
[LastName] NCHAR (10) NULL,
[Email] NVARCHAR (50) NULL,
[Password] NCHAR (10) NULL,
[Address] NCHAR (10) NULL,
[RefistrationOnTime] DATETIME NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
```
Registration :
MainWindow.xaml:
```
```
MainWindow.xaml.cs:
```
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Windows;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Login_Click(object sender, RoutedEventArgs e)
{
Login login = new Login();
login.Show();
Close();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
Reset();
}
public void Reset()
{
textBoxFirstName.Text = "";
textBoxLastName.Text = "";
textBoxEmail.Text = "";
textBoxAddress.Text = "";
passwordBox1.Password = "";
passwordBoxConfirm.Password = "";
}
private void button3_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Submit_Click(object sender, RoutedEventArgs e)
{
if (textBoxEmail.Text.Length == 0)
{
errormessage.Text = "Enter an email.";
textBoxEmail.Focus();
}
else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
errormessage.Text = "Enter a valid email.";
textBoxEmail.Select(0, textBoxEmail.Text.Length);
textBoxEmail.Focus();
}
else
{
string firstname = textBoxFirstName.Text;
string lastname = textBoxLastName.Text;
string email = textBoxEmail.Text;
string password = passwordBox1.Password;
if (passwordBox1.Password.Length == 0)
{
errormessage.Text = "Enter password.";
passwordBox1.Focus();
}
else if (passwordBoxConfirm.Password.Length == 0)
{
errormessage.Text = "Enter Confirm password.";
passwordBoxConfirm.Focus();
}
else if (passwordBox1.Password != passwordBoxConfirm.Password)
{
errormessage.Text = "Confirm password must be same as password.";
passwordBoxConfirm.Focus();
}
else
{
errormessage.Text = "";
string address = textBoxAddress.Text;
SqlConnection con = new SqlConnection("constr");
con.Open();
string cmdText = string.Format("SELECT ID FROM [dbo].[Registration] Where Email = '{0}' And Password = '{1}'", email, password);
SqlCommand cmd = new SqlCommand(cmdText, con);
object result = cmd.ExecuteScalar();
if (result != null)
{
errormessage.Text = "User existed";
passwordBoxConfirm.Focus();
}
else
{
SqlCommand cmd1 = new SqlCommand("Insert into [dbo].[Registration] (FirstName,LastName,Email,Password,Address) values('" + firstname + "','" + lastname + "','" + email + "','" + password + "','" + address + "')", con);
cmd1.CommandType = CommandType.Text;
cmd1.ExecuteNonQuery();
errormessage.Text = "You have Registered successfully.";
Reset();
}
con.Close();
}
}
}
}
```
Login:
```
Note: Please login here to view the features of this site. If you are new on this site then
please click on
Register
button
```
Login.xaml.cs:
```
public partial class Login : Window
{
public Login()
{
InitializeComponent();
}
MainWindow registration = new MainWindow();
Welcome welcome = new Welcome();
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBoxEmail.Text.Length == 0)
{
errormessage.Text = "Enter an email.";
textBoxEmail.Focus();
}
else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
errormessage.Text = "Enter a valid email.";
textBoxEmail.Select(0, textBoxEmail.Text.Length);
textBoxEmail.Focus();
}
else
{
string email = textBoxEmail.Text;
string password = passwordBox1.Password;
SqlConnection con = new SqlConnection("constr");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from [dbo].[Registration] where Email='" + email + "' and password='" + password + "'", con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
if (dataSet.Tables[0].Rows.Count > 0)
{
string username = dataSet.Tables[0].Rows[0]["FirstName"].ToString() + " " + dataSet.Tables[0].Rows[0]["LastName"].ToString();
welcome.TextBlockName.Text = username;
welcome.Show();
Close();
}
else
{
errormessage.Text = "Sorry! Please enter existing emailid/password.";
}
con.Close();
}
}
private void buttonRegister_Click(object sender, RoutedEventArgs e)
{
registration.Show();
Close();
}
}
```
Welcome:
```
```