private void Submit_Click(object sender, RoutedEventArgs e) //submit button function.
 {
     //listing contraints for email and password using if and Regex.
     if (EmailInput.Text.Length == 0)
     {
         errormessage.Text = "Enter an email.";                                                                                              //show error message.
         EmailInput.Focus();                                                                                                                 //will focus the email after the popup of error message.
     }
     else if (!Regex.IsMatch(EmailInput.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]$")) //regex constraints for email validation.
     {
         errormessage.Text = "Enter a valid email.";
         EmailInput.Select(0, EmailInput.Text.Length);
         EmailInput.Focus();
     }
     else
     {
         //assigning varibales for xaml input tags
         string firstname = FirstNameInput.Text;
         string lastname  = LastNameInput.Text;
         string email     = EmailInput.Text;
         string password  = passwordInput.Password;
         //constraints for password using if
         if (passwordInput.Password.Length == 0)
         {
             errormessage.Text = "Enter password.";
             passwordInput.Focus();
         }
         else if (passwordConfirmInput.Password.Length == 0)
         {
             errormessage.Text = "Enter Confirm password.";
             passwordConfirmInput.Focus();
         }
         else if (passwordInput.Password != passwordConfirmInput.Password)
         {
             errormessage.Text = "Confirm password must be same as password.";
             passwordConfirmInput.Focus();
         }
         else
         {
             errormessage.Text = "";
             string address = AddressInput.Text;
             //sql connection --- SSMS --> Server type = Database engine ; Auth --> Windows Auth ;
             SqlConnection con = new SqlConnection(@"Data Source=PRAVEENRAMESH;Initial Catalog=Login_DB;Integrated Security=True;");
             con.Open(); //create connection
             //insert values
             SqlCommand cmd = new SqlCommand("Insert into [Users] (FirstName,LastName,Email,Password,Address) values('" + firstname + "','" + lastname + "','" + email + "','" + password + "','" + address + "')", con);
             cmd.CommandType = CommandType.Text;
             cmd.ExecuteNonQuery(); //executenonquery to insert values
             con.Close();           //close connection after data inseration
             errormessage.Text = "You have Registered successfully.";
             Reset();               //reset the registration form
         }
     }
 }
        Welcome welcome         = new Welcome();                   //object for welcome class

        private void Login_Click(object sender, RoutedEventArgs e) //login button function
        {
            //constraints for login using if and regex
            if (EmailInput.Text.Length == 0)
            {
                errormessage.Text = "Enter an email.";
                EmailInput.Focus();
            }
            else if (!Regex.IsMatch(EmailInput.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.";
                EmailInput.Select(0, EmailInput.Text.Length);
                EmailInput.Focus();
            }
            else
            {
                string email    = EmailInput.Text;
                string password = passwordInput.Password;
                //sql connection --> to know env see MainWindow.xaml.cs sql comment line 94.
                SqlConnection con = new SqlConnection("Data Source=PRAVEENRAMESH;Initial Catalog=Login_DB;Integrated Security=True;");
                con.Open(); //create connection
                //select login values from db.
                SqlCommand cmd = new SqlCommand("Select * from dbo.Users where Email='" + email + "'  and password='******'", con);
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = cmd;
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);
                //check in db for data.
                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; //Sending value from one form to another form.
                    welcome.Show();                        //shows welcome window
                    Close();                               //close login window
                }
                else
                {
                    errormessage.Text = "Sorry! Please enter existing emailid/password.";
                }
                con.Close(); //close the connection.
            }
        }