} //fill a datagrid whith user needed to be cretated public static void Login(TextBox TextBox, PasswordBox passwordbox) { SqlConnection con; SqlCommand cmd; SqlDataReader reader; String connectionString = @"Data Source=L-LR0AXESR\SQLEXPRESS;Initial Catalog=WEB;User ID=Test;Password=Test"; try { con = new SqlConnection(connectionString); con.Open(); cmd = new SqlCommand("Select * from dbo.Credential where Mail=@CustomerEmail", con); cmd.Parameters.AddWithValue("@CustomerEmail", TextBox.Text.ToString()); reader = cmd.ExecuteReader(); if (reader.Read()) { string plain; // plain = passwordbox.Password.ToString(); //a effacer string encryptedString = Cryption.EncryptString(Cryption.key, passwordbox.Password.ToString()); // encrypted the password plain = encryptedString; if (reader["Password"].ToString().Equals(plain, StringComparison.InvariantCulture)) { message = "1"; //Used for the knowing if the password are the same UserInfo.CustomerEmail = TextBox.Text.ToString(); // registers the different user data UserInfo.CustomerName = reader["Name"].ToString(); UserInfo.CustomerRole = reader["Role"].ToString(); UserInfo.CustomerID = reader["ID"].ToString(); UserInfo.DomainID = reader["Domain_id"].ToString(); } } reader.Close(); reader.Dispose(); cmd.Dispose(); con.Close(); } catch (Exception ex) { message = ex.Message.ToString(); } } //Verifiyed the login information
} // Take the server name from the ID public static void Take_password() { Sql_Connection.conn.Open(); SqlCommand cmd2 = new SqlCommand("select Password from Credential where Name=@Name", Sql_Connection.conn); cmd2.Parameters.AddWithValue("@GName", AdminData.U_Name); SqlDataReader dr2; dr2 = cmd2.ExecuteReader(); if (dr2.Read()) { AdminData.U_password = dr2.GetString(0).ToString(); } dr2.Close(); AdminData.U_password_decrypted = Cryption.EncryptString(Cryption.key, AdminData.U_password.ToString()); Sql_Connection.conn.Close(); } // Take the password fo the new user from the database
private void New_User(object sender, RoutedEventArgs e) { ManagerData.M_Domain = UserInfo.DomainID; ManagerData.M_Mail = Mail_texybox.Text; ManagerData.M_Surname = Surname_texybox.Text; ManagerData.M_password = Password_texybox.Text; ManagerData.M_Name = Name_texybox.Text; ManagerData.M_password2 = Password2_texybox.Text; string role = "User"; if (ManagerData.M_password == ManagerData.M_password2) { string encryptedString = Cryption.EncryptString(Cryption.key, ManagerData.M_password); string plain2 = encryptedString; Sql_Connection.NewUser(ManagerData.M_Mail, ManagerData.M_Name, plain2, ManagerData.M_Surname, ManagerData.M_Domain, role); } else { MessageBox.Show("Password are not the Same ", "Info"); } }