public void CreateHashAndValidate() { string input = "Pass@1234"; string hash = ValueHashUtil.CreateHash(input); bool isValid = ValueHashUtil.ValidateHash(input, hash); Assert.AreEqual(isValid, true); }
public static int RegisterUser(UserDetailsTDO userDetails, string partnerName, List <KeyValuePair <string, string> > additionalData, string requestIpAddress, out int dbErrorCode, out string dbErrorMsg) { dbErrorCode = -1; dbErrorMsg = ""; if (string.IsNullOrWhiteSpace(userDetails.CompanyDetails.Name)) { userDetails.CompanyDetails = new CompanyDetailsDTO(); } if (string.IsNullOrWhiteSpace(userDetails.Password)) { dbErrorCode = 0; dbErrorMsg = "Unable to register user at this time. Invalid Password."; return(-1); } // hash user password userDetails.Password = ValueHashUtil.CreateHash(userDetails.Password); // get XML based on UserRegistrationDTO object XDocument xDoc = new XDocument(); using (var writer = xDoc.CreateWriter()) { var serializer = new DataContractSerializer(userDetails.GetType()); serializer.WriteObject(writer, userDetails); } // additional user info if (additionalData != null && additionalData.Count > 0) { XNamespace xNamespace = xDoc.Root.Attribute("xmlns").Value; xDoc.Root.LastNode.AddAfterSelf(new XElement(xNamespace + "additional-data", from T in additionalData select new XElement(xNamespace + "item", new XAttribute("type", T.Key), T.Value ))); } // db call return(new ProjectDB(ConfigurationHelper.GPD_Connection).AddUserDetails(xDoc, requestIpAddress, out dbErrorCode, out dbErrorMsg)); }
public static int AddUserDetails(XDocument userDetails, string requestIpAddress, out int errorCode, out string errorMsg) { int userId = -1; errorCode = -1; errorMsg = string.Empty; try { // hash user password userDetails.XPathSelectElement("//*[local-name()='password']").Value = ValueHashUtil.CreateHash(userDetails.XPathSelectElement("//*[local-name()='password']").Value); // add user details userId = new ProjectDB(Utility.ConfigurationHelper.GPD_Connection) .AddUserDetails(userDetails, requestIpAddress, out errorCode, out errorMsg); } catch (Exception exc) { log.Error("Unable to Add New User" + exc.ToString()); } return(userId); }
/// <summary> /// /// </summary> /// <param name="userEmail"></param> /// <param name="errorMsg"></param> public static bool ResetUserPassword(string userEmail, out string errorMsg) { bool retObj = false; errorMsg = string.Empty; try { string userPassword = Guid.NewGuid().ToString().Replace("-", ""); userPassword = userPassword.Substring(0, 8); DataSet dataSet = new UserDB(ConfigurationHelper.GPD_Connection).UpdateUserPassword(userEmail, ValueHashUtil.CreateHash(userPassword)); if (dataSet == null || dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0) { throw new Exception("No response from stored procedure."); } // send email string emailContentFile = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\App_Data\\" + "reset-user-password-email.htm"; string emailHtml = System.IO.File.ReadAllText(emailContentFile); emailHtml = emailHtml.Replace("{user-first-name}", dataSet.Tables[0].Rows[0]["first_name"].ToString()); emailHtml = emailHtml.Replace("{user-last-name}", dataSet.Tables[0].Rows[0]["last_name"].ToString()); emailHtml = emailHtml.Replace("{user-email-address}", dataSet.Tables[0].Rows[0]["email"].ToString()); emailHtml = emailHtml.Replace("{user-password}", userPassword); // send emaill retObj = SendEmail(userEmail, emailHtml); } catch (Exception exc) { log.Error("Unable to reset user password. ERROR: " + exc.ToString()); errorMsg = "Unable to Reset User Password."; } return(retObj); }
/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="userDetails"></param> public static bool UpdatetUserProfile(int userId, UserDetailsTDO userDetails, out string errorMsg) { try { // hash user password userDetails.Password = (string.IsNullOrEmpty(userDetails.Password)) ? null : ValueHashUtil.CreateHash(userDetails.Password); // get XML based on UserDetailsTDO object XDocument xDoc = new XDocument(); using (var writer = xDoc.CreateWriter()) { var serializer = new System.Runtime.Serialization.DataContractSerializer(userDetails.GetType()); serializer.WriteObject(writer, userDetails); } // update user details int errorCode; new ProjectDB(ConfigurationHelper.GPD_Connection).UpdateUserProfile(userId, xDoc, out errorCode, out errorMsg); return(errorCode == 0); } catch (Exception exc) { log.Error("Unable to Update User Profile. ERROR: " + exc.ToString()); errorMsg = "Unable to Update User Profile"; return(false); } }