public override bool Create(IModel m) { var user = (UserModel)m; var sql = string.Format(cSql, Guid.NewGuid(), user.LoginName, MD5Crypto.Encode(user.Password), DateTime.Now, "sys"); var result = utility.Exec(sql); return(result.Item1); }
public bool ValidatePassword(string password) { if (string.IsNullOrWhiteSpace(password)) { return(false); } var hash = MD5Crypto.Encode(password); return(hash.Equals(PasswordHash)); }
public void HashingPasswordTest() { var password = "******"; var expectedHash = MD5Crypto.Encode(password); var developer = EntitiesFactory.NewDeveloper(password: password).Get(); Assert.Equal(expectedHash, developer.PasswordHash); Assert.NotEqual(password, developer.PasswordHash); }
public User( string id, string name, string login, string password ) : this() { this.Id = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id; this.Password = MD5Crypto.Encode(VehicleStartup.Secret + password); this.SetData( name: name, login: login ); }
/// <summary> /// 校验帐号和密码 /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns>UserID/SessionID</returns> public KeyValuePair <string, string> Check(string p1, string p2) { var r = (UserModel)db.Read(p1); if (r.LoginName == p1 && r.Password == MD5Crypto.Encode(p2)) { if (!udb.Exists()) { ulogic.CreatePoint(r.ID, 1); } return(new KeyValuePair <string, string>(r.ID.ToString(), Guid.NewGuid().ToString())); } else { return(new KeyValuePair <string, string>()); } }
public Developer( Guid id, string name, string login, string cpf, string password, IEnumerable <DeveloperProject> developerProjects = null ) : base(id) { this.CPF = cpf; this.PasswordHash = MD5Crypto.Encode(password); _developerProjects = new List <DeveloperProject>(); SetData( name: name, login: login, developerProjects: developerProjects ); }
public async void CreateDeveloperTest( Status expectedStatus, bool validCPF = false ) { var developerDto = new DeveloperCreateDto { Name = RandomHelper.RandomString(), Login = RandomHelper.RandomString(), Password = RandomHelper.RandomNumbers(), CPF = RandomHelper.RandomNumbers(11) }; var developersPersisted = new List <Developer>(); _developerRepository.Setup(d => d.CreateAsync(Capture.In(developersPersisted))); _developerRepository.Setup(d => d.ExistByLoginAsync(developerDto.Login, default)) .ReturnsAsync(expectedStatus == Status.Conflict); _mockyRepository.Setup(m => m.ValidateCPFAsync(developerDto.CPF)) .ReturnsAsync(new Result <bool>(validCPF)); var service = new DeveloperService(_developerRepository.Object, _workRepository.Object, _mockyRepository.Object); var result = await service.CreateDeveloperAsync(developerDto); Assert.Equal(expectedStatus, result.Status); if (expectedStatus == Status.Success) { _developerRepository.Verify(d => d.CreateAsync(It.IsAny <Developer>()), Times.Once); _mockyRepository.Verify(d => d.ValidateCPFAsync(developerDto.CPF), Times.Once); var developer = developersPersisted.Single(); Assert.Equal(developerDto.Name, developer.Name); Assert.Equal(developerDto.Login, developer.Login); Assert.Equal(developerDto.CPF, developer.CPF); Assert.Equal(MD5Crypto.Encode(developerDto.Password), developer.PasswordHash); } else { _developerRepository.Verify(d => d.CreateAsync(It.IsAny <Developer>()), Times.Never); } }