/// <summary> /// ใช้ตรวจสอบ Username Password และสร้าง Session Cookie /// </summary> /// <param name="Username">Login Username</param> /// <param name="Password">Login Password</param> /// <param name="CreateCookie">สร้าง Cookie ด้วยไหม</param> /// <returns>ผลการล็อคอิน</returns> /// <example> /// clsSecurity.LoginChecker("offduiclub","off1234",false); /// clsSecurity.LoginChecker("offduiclub","off1234"); /// </example> public bool LoginChecker(string Username, string Password, bool CreateCookie = false) { bool rtnValue = false; DataTable dt = new DataTable(); clsDefault clsDefault = new clsDefault(); clsSQL clsSQL = new clsSQL(); StringBuilder strSQL = new StringBuilder(); #region SQL Query strSQL.Append("SELECT "); strSQL.Append("[User].UID,"); strSQL.Append("[User].Username,"); strSQL.Append("UserGroup.Name AS UserGroupName,"); strSQL.Append("ISNULL(UserGroup.Authority,'') AS GroupAuthority,"); strSQL.Append("ISNULL([User].Authority,'') AS UserAuthority "); strSQL.Append("FROM "); strSQL.Append("[User] "); strSQL.Append("INNER JOIN UserGroup "); strSQL.Append("ON [User].UserGroupUID=UserGroup.UID AND UserGroup.Active='1' "); strSQL.Append("WHERE "); strSQL.Append("[User].Username="******"Username "); strSQL.Append("AND [User].Password="******"Password "); strSQL.Append("AND [User].Active='1'"); #endregion dt = clsSQL.Bind( strSQL.ToString(), new string[, ] { { "" + _parameterChar + "Username", Username }, { "" + _parameterChar + "Password", Encrypt(Password) } }, _dbType, _cs ); if (dt != null && dt.Rows.Count > 0) { rtnValue = true; SetLoginSession( _sessionName, new string[] { dt.Rows[0]["UID"].ToString(), dt.Rows[0]["Username"].ToString(), dt.Rows[0]["UserGroupName"].ToString(), dt.Rows[0]["GroupAuthority"].ToString(), dt.Rows[0]["UserAuthority"].ToString() } ); if (CreateCookie) { clsDefault.CookieCreate(_sessionName, Encrypt(dt.Rows[0]["UID"].ToString())); } } return(rtnValue); }
/// <summary> /// ใช้ตรวจสอบ Username Password และสร้าง Session Cookie /// </summary> /// <param name="Username">Login Username</param> /// <param name="Password">Login Password</param> /// <param name="CreateCookie">สร้าง Cookie ด้วยไหม</param> /// <returns>ผลการล็อคอิน</returns> /// <example> /// clsSecurity.LoginChecker("offduiclub","off1234",false); /// clsSecurity.LoginChecker("offduiclub","off1234"); /// </example> public bool LoginChecker(string Username, string Password, bool CreateCookie = false) { #region Variable var result = false; var dt = new DataTable(); var clsDefault = new clsDefault(); var clsSQL = new clsSQL(_dbType, _cs); var strSQL = new StringBuilder(); #endregion #region Procedure #region SQLQuery strSQL.Append("SELECT "); strSQL.Append("A.UID,"); strSQL.Append("A.Username,"); strSQL.Append("B.Name AS UserGroupName,"); strSQL.Append((_dbType == clsSQL.DBType.MySQL?"IFNULL":"ISNULL") + "(B.Authority,'') AS GroupAuthority,"); strSQL.Append((_dbType == clsSQL.DBType.MySQL?"IFNULL":"ISNULL") + "(A.Authority,'') AS UserAuthority "); strSQL.Append("FROM "); strSQL.Append("[User] A "); strSQL.Append("INNER JOIN UserGroup B "); strSQL.Append("ON A.UserGroupUID=B.UID AND B.StatusFlag='A' "); strSQL.Append("WHERE "); strSQL.Append("A.Username="******"Username "); strSQL.Append("AND A.Password="******"Password "); strSQL.Append("AND A.StatusFlag='A'"); #endregion dt = clsSQL.Bind( strSQL.ToString(), new string[, ] { { "" + _parameterChar + "Username", Username }, { "" + _parameterChar + "Password", Encrypt(Password) } } ); if (dt != null && dt.Rows.Count > 0) { result = true; SetLoginSession( _sessionName, new string[] { dt.Rows[0]["UID"].ToString(), dt.Rows[0]["Username"].ToString(), dt.Rows[0]["UserGroupName"].ToString(), dt.Rows[0]["GroupAuthority"].ToString(), dt.Rows[0]["UserAuthority"].ToString() } ); if (CreateCookie) { clsDefault.CookieCreate(_sessionName, Encrypt(dt.Rows[0]["UID"].ToString())); } } #endregion return(result); }
/// <summary> /// ใช้ตรวจสอบ Username Password และสร้าง Session Cookie /// </summary> /// <param name="Username">Login Username</param> /// <param name="Password">Login Password</param> /// <param name="CreateCookie">สร้าง Cookie ด้วยไหม</param> /// <returns>ผลการล็อคอิน</returns> /// <example> /// clsSecurity.LoginChecker("offduiclub","off1234",false); /// clsSecurity.LoginChecker("offduiclub","off1234"); /// </example> public bool LoginChecker(string Username, string Password, bool CreateCookie = false) { bool rtnValue = false; DataTable dt = new DataTable(); clsDefault clsDefault = new clsDefault(); clsSQL clsSQL = new clsSQL(); StringBuilder strSQL=new StringBuilder(); #region SQL Query strSQL.Append("SELECT "); strSQL.Append("[User].UID,"); strSQL.Append("[User].Username,"); strSQL.Append("UserGroup.Name AS UserGroupName,"); strSQL.Append("ISNULL(UserGroup.Authority,'') AS GroupAuthority,"); strSQL.Append("ISNULL([User].Authority,'') AS UserAuthority "); strSQL.Append("FROM "); strSQL.Append("[User] "); strSQL.Append("INNER JOIN UserGroup "); strSQL.Append("ON [User].UserGroupUID=UserGroup.UID AND UserGroup.Active='1' "); strSQL.Append("WHERE "); strSQL.Append("[User].Username="******"Username "); strSQL.Append("AND [User].Password="******"Password "); strSQL.Append("AND [User].Active='1'"); #endregion dt = clsSQL.Bind( strSQL.ToString(), new string[,] { { "" + _parameterChar + "Username", Username }, { "" + _parameterChar + "Password", Encrypt(Password) } }, _dbType, _cs ); if (dt != null && dt.Rows.Count > 0) { rtnValue = true; SetLoginSession( _sessionName, new string[] { dt.Rows[0]["UID"].ToString(), dt.Rows[0]["Username"].ToString(), dt.Rows[0]["UserGroupName"].ToString(), dt.Rows[0]["GroupAuthority"].ToString(), dt.Rows[0]["UserAuthority"].ToString() } ); if (CreateCookie) { clsDefault.CookieCreate(_sessionName, Encrypt(dt.Rows[0]["UID"].ToString())); } } return rtnValue; }