using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace Kronos{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void LoginButton1_Click(object sender, EventArgs e) { string username = UserBox1.Text; string password = PassBox1.Text; if (ValidateUserNamePassword(username, password)) { MessageBox.Show("Succsess!", "Authentication Complete"); } else { MessageBox.Show("Invalid user name or password", "Invalid Login"); return; } } public bool ValidateUserNamePassword(string _username, string _password){ string connectionString = "Server=localhost;Database=kronos;User ID=root;Password=;"; using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "tsp_GetUserNameAndPassword"; SqlParameterCollection sqlParams = cmd.Parameters; sqlParams.AddWithValue("@UserName", _username); sqlParams.AddWithValue("@Password", _password); cn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow); if (dr.Read()) { // this will return true if a row matching the username and password is found. // this means that the user's input is valid return true; } else { return false; } dr.Close(); cn.Close(); }} }}