public void LoginSuccess() { string email = "*****@*****.**"; string password = "******"; if (!Context.Users.Any(a => a.Email == email)) { var passHash = HashEncryption.Hash(password); Context.Users.Add(new User { Email = email, Password = passHash, Name = "Test" }); Context.SaveChanges(); } LoginRequest request = (new LoginRequest { Email = email, Password = password }); //Act UserResponse respons = Client.Login(request); //Assert Assert.NotNull(respons); Assert.NotNull(respons.User); Assert.AreEqual(respons.Respons.Status, ServiceResponseStatus.Ok); Assert.AreEqual(respons.User.Email, email); }
public void TestMethod1() { string Pass = HashEncryption.Hash("TextPassword"); bool ValidatePass = HashEncryption.VerifyHashPassword(Pass, "TextPassword"); Assert.IsTrue(ValidatePass); }
// <summary> /// Se actualiza la infomación de un usuario /// </summary> /// <param name="request"></param> /// <returns>Regresa ibjeto de tipo UserDTO</returns> public ResponseDTO <int> Update(UserRequestDTO request) { request.User = request.User == null ? new UserDTO(request.Info.IdUser) : request.User; request.Info = request.Info == null ? new InfoDTO() : request.Info; request.User.Password = !string.IsNullOrEmpty(request.User.Password)? HashEncryption.Hash(request.User.Password):null; return(_userRequestRepository.Update(request)); }
// public void Add100Users() { for (int i = 0; i < 100; i++) { string userName = "******" + i; var passHash = HashEncryption.Hash(userName); Context.Users.Add(new User { Email = userName + "@a.a", Password = passHash, Name = userName }); Context.SaveChanges(); } }
public ServiceResponse Registration(User user, string password, string repeatPassword) { user.Email = user.Email.ToLower(); ValidationResult valid = userServiceValidation.Registration(user, password, repeatPassword); if (!valid.IsSucces) { return(new ServiceResponse(ServiceRespondStatus.Error, valid.ErrorList)); } user.Password = HashEncryption.Hash(password); context.Users.Add(user); context.SaveChanges(); return(new ServiceResponse()); }
public ServiceResponse ChangePassword(int userId, string oldPassword, string newPassword, string repeatNewPassword) { User user = GetUserById(userId); if (user == null) { return(new ServiceResponse(ServiceRespondStatus.Error, ValidationKey.NullUser.ToString(), MessageOperation.GetValidationMessage(ValidationKey.NullUser))); } ValidationResult passwordValidate = userServiceValidation.ChangePassword(user.Password, oldPassword, newPassword, repeatNewPassword); if (!passwordValidate.IsSucces) { return(new ServiceResponse(ServiceRespondStatus.Error, passwordValidate.ErrorList)); } user.Password = HashEncryption.Hash(newPassword); context.SaveChanges(); return(new ServiceResponse()); }
public void ProcessRequest(HttpContext context) { // set from an earlier in pipeline by CDNInterceptPipeline string minifyPath = StringUtil.GetString(context.Items["MinifyPath"]); if (string.IsNullOrEmpty(minifyPath)) { context.Response.StatusCode = 404; context.Response.End(); } UrlString url = new UrlString(minifyPath); string localPath = url.Path; string filePath = FileUtil.MapPath(localPath); // if the request is a .js file if (localPath.EndsWith(".js")) { HashEncryption hasher = new HashEncryption(HashEncryption.EncryptionProvider.MD5); if (!string.IsNullOrEmpty(localPath)) { // generate a unique filename for the cached .js version string cachedFilePath = FileUtil.MapPath(string.Format("/App_Data/MediaCache/{0}.js", hasher.Hash(url.ToString()))); // if it doesn't exist create it if (!FileUtil.FileExists(cachedFilePath)) { // if the original file exsits minify it if (FileUtil.FileExists(filePath)) { JsMinifier minifier = new JsMinifier(); string minified = minifier.Minify(filePath); FileUtil.WriteToFile(cachedFilePath, minified); } } if (FileUtil.FileExists(cachedFilePath)) { context.Response.ClearHeaders(); context.Response.Cache.SetExpires(DateTime.Now.AddDays(14)); context.Response.AddHeader("Content-Type", "application/x-javascript; charset=utf-8"); context.Response.WriteFile(cachedFilePath); context.Response.End(); _success = true; } } } // if the request is a .css file else if (localPath.EndsWith(".css")) { HashEncryption hasher = new HashEncryption(HashEncryption.EncryptionProvider.MD5); if (!string.IsNullOrEmpty(localPath)) { // generate a unique filename for the cached .css version string cachedFilePath = FileUtil.MapPath(string.Format("/App_Data/MediaCache/{0}.css", hasher.Hash(url.ToString()))); // if it doesn't exist create it if (!FileUtil.FileExists(cachedFilePath)) { // if the original file exsits minify it if (FileUtil.FileExists(filePath)) { CssMinifier minifier = new CssMinifier(); string minified = CssMinifier.Minify(FileUtil.ReadFromFile(filePath)); // if Css Processing is enabled, replace any urls inside the css file. if (CDNSettings.ProcessCss) { // find all css occurences of url([url]) Regex reReplaceUrl = new Regex("url\\(\\s*['\"]?([^\"')]+)['\"]?\\s*\\)"); try { // replacing url([url]) with url([cdnUrl]) in css minified = reReplaceUrl.Replace(minified, (m) => { string oldUrl = ""; if (m.Groups.Count > 1) oldUrl = m.Groups[1].Value; if (WebUtil.IsInternalUrl(oldUrl)) { if (oldUrl.StartsWith(".")) { oldUrl = VirtualPathUtility.Combine(url.Path, oldUrl); } string newUrl = CDNManager.ReplaceMediaUrl(oldUrl, string.Empty); if (!string.IsNullOrEmpty(newUrl)) { return m.Value.Replace(m.Groups[1].Value, newUrl); } } return m.Value; }); } catch (Exception ex) { Log.Error("Minify error", ex, this); } } FileUtil.WriteToFile(cachedFilePath, minified); } } if (FileUtil.FileExists(cachedFilePath)) { context.Response.ClearHeaders(); context.Response.Cache.SetExpires(DateTime.Now.AddDays(14)); context.Response.AddHeader("Content-Type", "text/css; charset=utf-8"); context.Response.TransmitFile(cachedFilePath); context.Response.End(); _success = true; } } } }
/// <summary> /// Se agrega información de usuarios nuevos /// </summary> /// <param name="request"></param> /// <returns>Regresa id de usuario</returns> public ResponseDTO <int> Add(UserRequestDTO request) { request.User.Password = HashEncryption.Hash(request.User.Password); return(_userRequestRepository.Add(request)); }
public void ProcessRequest(HttpContext context) { // set from an earlier in pipeline by CDNInterceptPipeline string minifyPath = StringUtil.GetString(context.Items["MinifyPath"]); if (string.IsNullOrEmpty(minifyPath)) { context.Response.StatusCode = 404; context.Response.End(); } UrlString url = new UrlString(minifyPath); string localPath = url.Path; string filePath = FileUtil.MapPath(localPath); // if the request is a .js file if (localPath.EndsWith(".js")) { HashEncryption hasher = new HashEncryption(HashEncryption.EncryptionProvider.MD5); if (!string.IsNullOrEmpty(localPath)) { // generate a unique filename for the cached .js version string cachedFilePath = FileUtil.MapPath(string.Format("/App_Data/MediaCache/{0}.js", hasher.Hash(url.ToString()))); // if it doesn't exist create it if (!FileUtil.FileExists(cachedFilePath)) { // if the original file exsits minify it if (FileUtil.FileExists(filePath)) { JsMinifier minifier = new JsMinifier(); string minified = minifier.Minify(filePath); FileUtil.WriteToFile(cachedFilePath, minified); } } if (FileUtil.FileExists(cachedFilePath)) { context.Response.ClearHeaders(); context.Response.Cache.SetExpires(DateTime.Now.AddDays(14)); context.Response.AddHeader("Content-Type", "application/x-javascript; charset=utf-8"); context.Response.WriteFile(cachedFilePath); context.Response.End(); _success = true; } } } // if the request is a .css file else if (localPath.EndsWith(".css")) { HashEncryption hasher = new HashEncryption(HashEncryption.EncryptionProvider.MD5); if (!string.IsNullOrEmpty(localPath)) { // generate a unique filename for the cached .css version string cachedFilePath = FileUtil.MapPath(string.Format("/App_Data/MediaCache/{0}.css", hasher.Hash(url.ToString()))); // if it doesn't exist create it if (!FileUtil.FileExists(cachedFilePath)) { // if the original file exsits minify it if (FileUtil.FileExists(filePath)) { CssMinifier minifier = new CssMinifier(); string minified = CssMinifier.Minify(FileUtil.ReadFromFile(filePath)); // if Css Processing is enabled, replace any urls inside the css file. if (CDNSettings.ProcessCss) { // find all css occurences of url([url]) Regex reReplaceUrl = new Regex("url\\(\\s*['\"]?([^\"')]+)['\"]?\\s*\\)"); try { // replacing url([url]) with url([cdnUrl]) in css minified = reReplaceUrl.Replace(minified, (m) => { string oldUrl = ""; if (m.Groups.Count > 1) { oldUrl = m.Groups[1].Value; } if (WebUtil.IsInternalUrl(oldUrl)) { if (oldUrl.StartsWith(".")) { oldUrl = VirtualPathUtility.Combine(url.Path, oldUrl); } string newUrl = CDNManager.ReplaceMediaUrl(oldUrl, string.Empty); if (!string.IsNullOrEmpty(newUrl)) { return(m.Value.Replace(m.Groups[1].Value, newUrl)); } } return(m.Value); }); } catch (Exception ex) { Log.Error("Minify error", ex, this); } } FileUtil.WriteToFile(cachedFilePath, minified); } } if (FileUtil.FileExists(cachedFilePath)) { context.Response.ClearHeaders(); context.Response.Cache.SetExpires(DateTime.Now.AddDays(14)); context.Response.AddHeader("Content-Type", "text/css; charset=utf-8"); context.Response.TransmitFile(cachedFilePath); context.Response.End(); _success = true; } } } }