public string ChangePassword(PreferenceModel pref) { uas_User user = pref.db.uas_User.Where(u => u.UserID == SessionHelper.LoginStatus.UserID).FirstOrDefault(); try { string encryptedNewPassword = UtilityFunction.EncryptPassword(pref.NewPasswordOne); user.Password = encryptedNewPassword; user.ModifiedBy = SessionHelper.LoginStatus.UserID; user.ModifiedDate = DateTime.Now; pref.db.Entry(user).State = System.Data.Entity.EntityState.Modified; pref.db.SaveChanges(); } catch (Exception ex) { Debug.Write("Change password: "******"Change password: Error changing if force change password."); } } return("success"); }
public string checkOldPass(PreferenceModel pref) { uas_User user = pref.db.uas_User.Where(u => u.UserID == SessionHelper.LoginStatus.UserID).FirstOrDefault(); if (UtilityFunction.EncryptPassword(pref.Password) == user.Password) { return("success"); } else if (String.IsNullOrEmpty(user.Password) && user.ChangePassword && UtilityFunction.EncryptPassword(pref.Password) == user.TempPassword) { return("success"); } return("fail"); }
private LoginStatus LoginVentureLogic(LoginInfo loginInfo) { LoginStatus loginStatus = null; Debug.WriteLine("AccountController.Venture LoginVentureLogic Authenticate User: "******"@")) //{ // string before = loginInfo.LoginID.Substring(0, loginInfo.LoginID.IndexOf("@")); // string mid = loginInfo.LoginID.Substring(loginInfo.LoginID.IndexOf("@") + 1); // if (mid.Contains(".")) // { // mid = mid.Substring(0, mid.IndexOf(".")); // } // loginInfo.LoginID = before; // loginInfo.Domain = mid; //} //string passkey = UtilityFunction.EncryptPassKey(loginInfo.LoginID); string passkey = UtilityFunction.EncryptPassKey(loginInfo.LoginID); string pwd = UtilityFunction.EncryptPassword(loginInfo.Password); // Debug.WriteLine("Authenticate User webclient.AuthenticateUser"); PackingFunction(); string validation = String.Empty; try { validation = UAS.Business.LocalClient.AuthenticateLocalUser(passkey, loginInfo.Domain, loginInfo.LoginID, loginInfo.Password); } catch (Exception excptn) { validation = "<record><errormessage>" + excptn.Message + "</errormessage></record>"; Debug.WriteLine("Authenticate User Venture exception: " + excptn.Message); } Debug.WriteLine("Authenticate User Venture validation: " + validation); if (!string.IsNullOrEmpty(validation)) { XmlDocument xDoc = new XmlDocument(); loginStatus = new LoginStatus(); try { xDoc.LoadXml(validation); loginStatus.UserID = Convert.ToInt32(xDoc.GetElementsByTagName("userid")[0].InnerText); loginStatus.EnterpriseID = Convert.ToInt32(xDoc.GetElementsByTagName("enterprise_id")[0].InnerText); /* Copied over by LAK, 1/28/2015 * Deleted by RRB 12/20/14 - Group is part of the groupPermissionSets * string groupId = xDoc.GetElementsByTagName("enterprise_id")[0].InnerText; * if ( !String.IsNullOrEmpty(groupId) ) * { * loginStatus.GroupID = Convert.ToInt32(groupId); * } */ // Fill with dummy for now - should probably be deleted from the structure. loginStatus.GroupID = 0; loginStatus.appGroupPermissions = new List <AppGroupPermissions>(); AppGroupPermissions agp = new AppGroupPermissions(); agp.groupPermissionSets = new List <GroupPermissionSet>(); string appId = xDoc.GetElementsByTagName("applicationid")[0].InnerText; if (!String.IsNullOrEmpty(appId)) { agp.ApplicationID = Convert.ToInt32(appId); } loginStatus.appGroupPermissions.Add(agp); // Get the Group Security Sets XmlNode nodeAppPerms = xDoc.SelectSingleNode("record/application_permissions"); XmlNodeList xnlGrpPrmList = nodeAppPerms.SelectNodes("group_permission"); bool enterpriseWideGroup = false; foreach (XmlNode xnGrpPrm in xnlGrpPrmList) { GroupPermissionSet gps = new GroupPermissionSet(); gps.GroupID = Convert.ToInt32(xnGrpPrm.Attributes.GetNamedItem("id").Value); if (gps.GroupID == 0) { enterpriseWideGroup = true; } gps.PermissionSet = xnGrpPrm.InnerText; loginStatus.appGroupPermissions[0].groupPermissionSets.Add(gps); } XmlNode nodeAuthGroups = nodeAppPerms.SelectSingleNode("authorizedGroups"); XmlNodeList xnlAuthGroupList = nodeAuthGroups.SelectNodes("groupId"); if (enterpriseWideGroup == false) { List <int> authGroups = new List <int>(); foreach (XmlNode xnAuthGroup in xnlAuthGroupList) { int grp = Convert.ToInt32(xnAuthGroup.InnerText); authGroups.Add(grp); } loginStatus.appGroupPermissions[0].authorizedGroups = authGroups;//.ToArray(); } else { loginStatus.appGroupPermissions[0].authorizedGroups = new int[] { 0 }.ToList(); } // loginStatus.PermissionSet = xDoc.GetElementsByTagName("permissions")[0].InnerText; if (loginStatus.appGroupPermissions.Count == 0 || loginStatus.appGroupPermissions[0].groupPermissionSets.Count == 0) { Exception e = new Exception(@"User not authorized for this application."); e.Data["noAuth"] = true; throw e; } loginStatus.Status = Convert.ToChar(xDoc.GetElementsByTagName("statusflag")[0].InnerText.Substring(0, 1)); loginStatus.UserKey = xDoc.GetElementsByTagName("userkey")[0].InnerText; loginStatus.EmailAddress = xDoc.GetElementsByTagName("useremail")[0].InnerText; loginStatus.FirstName = xDoc.GetElementsByTagName("userfirstname")[0].InnerText; loginStatus.LastName = xDoc.GetElementsByTagName("userlastname")[0].InnerText; Debug.WriteLine("AuthenticateUser FirstName LastName: " + loginStatus.FirstName + " " + loginStatus.LastName); loginStatus.SecureDomain = Convert.ToBoolean(xDoc.GetElementsByTagName("securedomain")[0].InnerText); loginStatus.IsAdmin = xDoc.GetElementsByTagName("role")[0].InnerText.ToLower().Contains("admin") ? true : false; loginStatus.ErrorMessage = xDoc.GetElementsByTagName("errormessage")[0].InnerText; Debug.WriteLine("AuthenticateUser ls.ErrorMessage: " + loginStatus.ErrorMessage); } catch (Exception excptn) { if (excptn.Data.Contains("noAuth")) { loginStatus.ErrorMessage = excptn.Message; Debug.WriteLine("Not authorized: " + excptn.Message); } else { string msg = "AuthenticateUser XML conversion exception: " + excptn.Message; Debug.WriteLine(msg); loginStatus.ErrorMessage = "Invalid username or password: "******"UserIsAdm"] = loginStatus.IsAdmin.ToString(); } } return(loginStatus); }