private void LogonMessage(Login1.loginResult ret) { this.Label1.Text = Login1.getLogonMsg(ret, this.TXT_USERNAME.Text); if (ret == Login1.loginResult.logPwdInvalid || ret == Login1.loginResult.logPwdEmpty || ret == Login1.loginResult.logJustLocked) { MyPage.SetFocus(this, this.TXT_PASSWORD); } else { MyPage.SetFocus(this, this.TXT_USERNAME); } }
protected void signin_Click(object sender, EventArgs e) { if (TXT_USERNAME.Text.ToString().Equals("")) { Response.Write("<script>alert('User Id Tidak Boleh Kosong')</script>"); MyPage.SetFocus(this, this.TXT_USERNAME); return; } else if (TXT_PASSWORD.Text.ToString().Equals("")) { Response.Write("<script>alert('Password Tidak Boleh Kosong')</script>"); MyPage.SetFocus(this, this.TXT_PASSWORD); return; } string nexturl = ""; if (!this.logon) { this.hash_password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TXT_PASSWORD.Text, "sha1"); } this.connectionString = Login1.decryptConnStr(ConfigurationSettings.AppSettings["MRSDATALOGIN"]); using (DbConnection conn = new DbConnection(this.connectionString)) { try { Login1.loginResult flag = Login1.ValidateLogin(this.TXT_USERNAME.Text, this.TXT_PASSWORD.Text, conn, this.dbtimeout, this.logon, base.Request.UserHostAddress); Login1.loginResult loginResult = flag; if (loginResult != Login1.loginResult.logSuccess) { if (loginResult != Login1.loginResult.logPwdExpired) { if (loginResult != Login1.loginResult.logPwdDefault) { this.LogonMessage(flag); } else { System.Web.Security.FormsAuthentication.SetAuthCookie(this.TXT_USERNAME.Text, false); this.Session.Add("UserID", this.TXT_USERNAME.Text); nexturl = "Change_Password.aspx?initial"; } } else { System.Web.Security.FormsAuthentication.SetAuthCookie(this.TXT_USERNAME.Text, false); this.Session.Add("sha1", this.hash_password); this.Session.Add("UserID", this.TXT_USERNAME.Text); nexturl = "Change_Password.aspx?expired"; } } else { object[] lgparam = new object[] { this.TXT_USERNAME.Text, base.Request.UserHostAddress }; conn.ExecuteNonQuery(Login1.SP_LOGINSTARTED, lgparam, this.dbtimeout); System.Web.Security.FormsAuthentication.SetAuthCookie(this.TXT_USERNAME.Text, false); nexturl = this.AuthenticateUser(conn); } } catch (Exception ex) { string errmsg = ex.Message; if (errmsg.IndexOf("Last Query: exec SU_USERLOGINGIN") > 0) { errmsg = errmsg.Substring(0, errmsg.IndexOf("Last Query:")); this.Label1.Text = errmsg; } else { Response.Write("<!-- ex msg: " + ex.Message.Replace("-->", "--)") + " -->\n"); this.LogonMessage(Login1.loginResult.logUnknown); } } } if (nexturl != "") { Session.Add("ConnString", _conn); Session.Add("DbTimeOut", dbtimeout); Response.Redirect(nexturl); } }
private static string getLogonMsg(Login1.loginResult ret, string user) { string msg = string.Empty; switch (ret) { case Login1.loginResult.logNotFound: if (user != string.Empty) { msg = "Invalid UserID/Password!"; } break; case Login1.loginResult.logHasLogon: msg = "User is currently logged in!"; break; case Login1.loginResult.logLocked: msg = "User ID is Locked, Please contact your System Administrator!"; break; case Login1.loginResult.logPwdEmpty: msg = "Please type in your password..."; break; case Login1.loginResult.logPwdInvalid: msg = "Invalid UserID/Password"; break; case Login1.loginResult.logJustLocked: msg = "User ID is Locked, Please contact your System Administrator!"; break; case Login1.loginResult.logGrantInvalid: msg = "Server Error : Permission Denied for '" + user.ToUpper() + "'"; break; case Login1.loginResult.logAuthFail: msg = "Login failed. Unable to Authenticate!"; break; case Login1.loginResult.logNoLOSAccess: msg = "User does not have access to application!"; break; case Login1.loginResult.logNoMenuAccess: msg = "Menu Access Not Yet Defined For This User."; break; case Login1.loginResult.logSessionLost: msg = "Session Lost... Please Login"; break; case Login1.loginResult.logReLogin: msg = "Please Re-Login"; break; case Login1.loginResult.logUnknown: msg = "Server Error : Unknown Error"; break; } return(msg); }