public bool ValidateToken(string DBPath, string DBPwd, string encryptedtoken, ref string message) { bool Validate = true; try { AES objpwd = new AES(); //DAL_LoginForm obj_DALLoginForm = new DAL_LoginForm(); //DAL_UserMgt obj_UserMgt = new DAL_UserMgt(); DAL_UserMgt obj_UserMgt = new DAL_UserMgt(); Hashtable ht = new Hashtable(); encryptedtoken = objpwd.AES_Decrypt(encryptedtoken); ht = (Hashtable)JsonConvert.DeserializeObject((encryptedtoken), (typeof(Hashtable))); int cid = Convert.ToInt16(ht["cid"]); string username = ht["username"].ToString(); string password = ht["password"].ToString(); int errno = 0; string errstring = string.Empty; string ADDomain = string.Empty; bool ADLogin = false; DataTable dtUserDetails = new DataTable(); //obj_UserMgt.GetUserDetails(ref DBPath, ref DBPwd, ref cid, ref username, ref password, ref ADDomain, ref ADLogin, ref dtUserDetails, ref _ErrNo, ref ErrString); //var result = obj_UserMgt.GetUserDetails(new Tuple<int, string, string, string, bool>(cid, username, password, ADDomain, ADLogin)); obj_UserMgt.GetUserDetails(DBPath, DBPwd, cid, username, password, ADDomain, ADLogin, ref errno, ref errstring, ref dtUserDetails); if (dtUserDetails.Rows.Count == 0) { Validate = false; message = "Invalid Token"; } } catch { Validate = false; message = "Invalid Token"; } return(Validate); }
public HttpResponseMessage Auth(csUserMgt obj) { ResponseObject res = new ResponseObject(); try { string ErrString = string.Empty; DataSet ds = new DataSet(); AES objpwd = new AES(); DAL_UserMgt obj_UserMgt = new DAL_UserMgt(); DataTable dtUserDetails = new DataTable(); int cid = CID; //obj.int_SiteID; string username = obj.str_UserName; string ADDomain = string.Empty; bool ADLogin = false; int errno = 0; string errstring = string.Empty; string pwd = objpwd.AES_Encrypt(obj.str_Password); //var result = obj_UserMgt.GetUserDetails(new Tuple<int, string, string, string, bool>(cid, username, pwd, ADDomain, ADLogin)); obj_UserMgt.GetUserDetails(DBPath, DBPwd, cid, username, pwd, ADDomain, ADLogin, ref errno, ref errstring, ref dtUserDetails); //dtUserDetails = result.dsUserdetails.Tables[0]; if (dtUserDetails != null && dtUserDetails.Rows.Count > 0) { if (pwd == dtUserDetails.Rows[0]["Password"].ToString()) { Hashtable ht = new Hashtable(); ht.Add("cid", cid); ht.Add("userid", dtUserDetails.Rows[0]["UserID"].ToString()); ht.Add("username", username); ht.Add("ledgerid", dtUserDetails.Rows[0]["LedgerID"]); ht.Add("password", dtUserDetails.Rows[0]["Password"].ToString()); ht.Add("groupid", dtUserDetails.Rows[0]["GroupID"].ToString()); ht.Add("groupname", dtUserDetails.Rows[0]["GroupName"].ToString()); string encrypttoken = JsonConvert.SerializeObject(ht); encrypttoken = objpwd.AES_Encrypt(encrypttoken); DataSet dsConfigParam = new DataSet(); dsConfigParam = obj_UserMgt.GetConfigParam(DBPath, DBPwd, cid, Convert.ToInt32(dtUserDetails.Rows[0]["GroupID"])); dsConfigParam.Tables[0].TableName = "ConfigParam"; dsConfigParam.Tables[1].TableName = "GroupGeneralSetting"; dsConfigParam.Tables[2].TableName = "BusinessPeriod"; int salesmanid = obj_UserMgt.GetSalesmanIDByLedgerID(DBPath, DBPwd, cid, Convert.ToInt32(dtUserDetails.Rows[0]["ledgerid"])); res.respdata = new User() { userid = Convert.ToInt32(dtUserDetails.Rows[0]["UserID"]), username = username, ledgerid = Convert.ToInt32(dtUserDetails.Rows[0]["ledgerid"]), groupid = Convert.ToInt16(dtUserDetails.Rows[0]["GroupID"]), token = encrypttoken, configparam = dsConfigParam, salesmanid = salesmanid }; } else { res.errno = 1; res.errdesc = "Wrong password"; } } else { res.errno = 1; res.errdesc = "Login failed"; } //} return(Request.CreateResponse(HttpStatusCode.OK, res)); } catch (Exception e) { //throw e; res.errno = 1; res.errdesc = e.Message; return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, res)); } }