private void Login_Action() { try { string Username = txt_username.text.ToUpper(); string Password = txt_password.text; Point_Of_SalesEntities = new POS_Entities(util.CheckDatabaseConnection()); string ret = "success"; // Get data User var dataUser = (from User in Point_Of_SalesEntities.TUsers from Role in Point_Of_SalesEntities.TRoles.Where(r => r.Role_id == User.Role_id) select new { User = User, Role = Role }) .Where(s => s.User.Username.ToUpper().Contains(Username)) .FirstOrDefault(); var dataUser1 = Point_Of_SalesEntities.TUsers.Where(x => x.Username.ToUpper().Contains(Username)).ToList(); //cek Password & Delete user string Password_hash = string.Join("", MD5.Create().ComputeHash( Encoding.ASCII.GetBytes(Password)).Select(s => s.ToString("x2"))); if (dataUser == null || dataUser.User.password.Trim() != Password_hash || dataUser.User.is_deleted == true) { //raiseLoginAttempt(Username); MessageBox.Show("username/password anda salah", "Error Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } //cek active if (dataUser != null && dataUser.User.is_active == false) { // ret = "Please contact your Administrator to Activate your account"; MessageBox.Show("Akun anda tidak aktif/terblokir, Silahkan hubungi admin untuk mengaktifkan kembali akun anda", "Error Login", MessageBoxButtons.OK, MessageBoxIcon.Error); // raiseLoginAttempt(Username); } if (dataUser != null && dataUser.User.password.Trim() == Password_hash && dataUser.User.is_deleted == false && dataUser.User.is_active == true) { MessageBox.Show("Login Sukses Selamat datang User: "******"Login Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information); //register session var _sessions = Properties.Settings.Default; _sessions._username = dataUser.User.Username; _sessions._userID = dataUser.User.User_id; _sessions.password = txt_password.text.Replace(Environment.NewLine, ""); _sessions._userRole = dataUser.User.Role_id; _sessions._userRolename = dataUser.Role.Role_Name; if (cb_remember.Checked == true) { _sessions.remembered_password = txt_password.text; _sessions.remembered_userid = txt_username.text; _sessions.Save(); } FormHome fh = new FormHome(); fh.Show(); this.Hide(); } } catch (Exception) { MessageBox.Show("Koneksi gagal silahkan periksa konfigurasi koneksi database", "Error Koneksi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Notification_Form(FormHome FormHome) { Home = FormHome; InitializeComponent(); }