public string AuthenticateUser(string UserName, string Password, bool RememberME) { DataSet objDS = new DataSet(); LoginModel objLoginModel = new LoginModel(); AccountsDAL objAccountsDAL = new AccountsDAL(); objDS = objAccountsDAL.CheckAccountExists(UserName, Password); if (objDS.Tables.Count > 0) { DataTable dataTable = objDS.Tables[0]; if (dataTable.Rows.Count > 0) { List<LoginModel> _LoginList = new List<LoginModel>(); foreach (DataRow row in dataTable.Rows) { objLoginModel = new LoginModel { AccountID = Convert.ToInt64(row["AccountID"]), Username = row["UserName"].ToString(), Password = row["password"].ToString(), AccountTitle = row["AccountTitle"].ToString(), ProfileImage = row["ProfileImage"].ToString(), }; _LoginList.Add(objLoginModel); } objLoginModel = _LoginList.Single(); } else { return "false"; } } if (objLoginModel.AccountID > 0) { if (RememberME) { SetCookieRememberMe("CLU", objLoginModel.Username.ToString(), DateTime.Now, new TimeSpan(30, 0, 0, 0)); } SetCookie("ID", objLoginModel.AccountID.ToString()); SetCookie("AccountTitle", objLoginModel.AccountTitle); SetCookie("PImage", objLoginModel.ProfileImage); FormsAuthentication.SetAuthCookie(objLoginModel.Username, true); FormsAuthentication.RedirectFromLoginPage(objLoginModel.Username, false); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, "user", DateTime.Now, DateTime.Now.AddMinutes(3), true, "fabiano!", FormsAuthentication.FormsCookiePath); // Create encrypted cookie string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } // Set and done Response.Cookies.Add(cookie); //Necessary, otherwise UserData property gets lost return "true"; } if (objLoginModel.AccountID < 1) { return "false"; } return String.Empty; }
public String getPassword(String userId, String mailId) { string result = "false"; string dpwd = ""; AccountsDAL objLogin = new AccountsDAL(); string pwd = ""; string username = ""; string mailid = ""; DataSet objDS = new DataSet(); objDS = objLogin.getPassword(userId, mailId); if (objDS.Tables.Count > 0) { if (objDS.Tables[0].Rows.Count > 0) { pwd = objDS.Tables[0].Rows[0]["Password"].ToString(); username = objDS.Tables[0].Rows[0]["UserName"].ToString(); mailid = objDS.Tables[0].Rows[0]["PrimaryEmail"].ToString(); //decryption dpwd = Cryptography.Cryptography.Decrypt(pwd); SendEmail objSendEmail = new SendEmail(); Boolean btnIsMailSent = objSendEmail.sendRecoveredPasswordMail(username, mailid, dpwd); if (btnIsMailSent == true) { result = "1"; } else { result = "2"; } } else { result = "0"; } } else { return "0"; } return result; }