Exemple #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            object retPass = new object();
            //validate username and password
            string passToValidate = string.Empty;
            string userName       = string.Empty;

            userName = lognameRadMaskedEditBox.Text.ToUpper();

            //Hardcoded password for admin
            if (userName == "ADMIN")
            {
                if (txtPassword.Text.ToLower() == "adm1n")
                {
                    NBConfig.BLoggedIn     = true;
                    NBConfig.LoginTime     = DateTime.Now;
                    NBConfig.ValidUserName = userName;
                    NBConfig.RetrieveGMID();
                    NBConfig.RetrieveGBID();
                    NBConfig.ValidUserID = -1;
                    ////record the time users authenticated
                    //this.Close();
                    //return;
                    frmMain frm = new frmMain();
                    frm.MaximizeBox = false;
                    frm.WindowState = FormWindowState.Maximized;
                    this.Close();
                    frm.Show();
                }
            }
            try
            {
                passToValidate = staffTableAdapter.RetrievePassword(lognameRadMaskedEditBox.Text.ToUpper()).ToString();
                if (passToValidate == GetMD5Hash(txtPassword.Text))
                {
                    NBConfig.ValidUserID   = int.Parse(staffTableAdapter.RetrieveUserID(userName).ToString());
                    NBConfig.BLoggedIn     = true;
                    NBConfig.LoginTime     = DateTime.Now;
                    NBConfig.ValidUserName = userName;
                    NBConfig.RetrieveGMID();
                    NBConfig.RetrieveGBID();
                    //Also get the ID of the current week's date
                    //record the time users authenticated
                    helper.SysLog(this.GetType().Name, NBConfig.ValidUserName, "Login");
                    //this.Close();
                    //return;
                }
                else
                {
                    MessageBox.Show("Wrong username/password!", "SMS - Error Notification");
                    lognameRadMaskedEditBox.Focus();
                    lognameRadMaskedEditBox.SelectAll();
                }
            }
            catch (MySqlException mex)
            {
                helper.ErrorMessage("Tidak ada koneksi ke Database. Segera hubungi administrator." + mex.StackTrace);
            }
            catch (Exception ex)
            {
                helper.ErrorMessage("Ada masalah untuk login ke system. Segera hubungi administrator.");
                lognameRadMaskedEditBox.Focus();
                lognameRadMaskedEditBox.SelectAll();
                //MessageBox.Show(ex.Message);
            }
            this.Close();
        }