// This command will accept the entries from the create account form. // It will save the information for all of the Users to the database. public bool UserDataSave(string username, string password) { HDClasses.Users create = new HDClasses.Users(); System.Data.SqlClient.SqlConnection sqlConnection1 = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Lioness\\Documents\\GitHub\\HRHelpdesk\\HRHelpdeskApp\\HRHelpdeskApp\\HRHelpdeskApp\\HDDatabase.mdf"); using (sqlConnection1) { string CheckUser = "******" + username + "'"; System.Data.SqlClient.SqlCommand CheckUsername = new System.Data.SqlClient.SqlCommand(CheckUser, sqlConnection1); sqlConnection1.Open(); using (SqlDataReader read = CheckUsername.ExecuteReader()) { while (read.Read()) { create.Username = read["Username"].ToString(); create.Password = read["Password"].ToString(); } } sqlConnection1.Close(); if (create.Username == username) { bool AddUser = true; return(AddUser); } else { bool AddUser = false; return(AddUser); } } }
// This command will retrieve the user's provided username and password. // If they match, it will return true, allowing access. // If they do not match, it will return false and the user will be given another chance // to input their information again. public bool SignInRetrieval(string Username, string Password) { HDClasses.Users signin = new HDClasses.Users(); System.Data.SqlClient.SqlConnection sqlConnection1 = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Lioness\\Documents\\GitHub\\HRHelpdesk\\HRHelpdeskApp\\HRHelpdeskApp\\HRHelpdeskApp\\HDDatabase.mdf"); using (sqlConnection1) { string data = "Select * from Login where Username = '******'"; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(data, sqlConnection1); sqlConnection1.Open(); using (SqlDataReader read = cmd.ExecuteReader()) { while (read.Read()) { signin.Username = read["UserName"].ToString(); signin.Password = read["Password"].ToString(); } } } sqlConnection1.Close(); if (signin.Username == Username && signin.Password == Password) { bool signIn = true; return(signIn); } else { bool signIn = false; return(signIn); } }