public async Task <User> Authenticate(string usernameString, string passwordString) { string encodedPassword = UserTools.ConvertInputTextToSha512(passwordString); User user = await Task.Run(() => _repositoryContext.Users.SingleOrDefault(x => x.NickName == usernameString && x.Password == encodedPassword)); return(user); }
private void InitUsers(ModelBuilder modelBuilder) { modelBuilder.Entity <User>().HasData(new User { Id = 1, NickName = UserTools.ANONYMOUS_USER_NICKNAME, Password = UserTools.ConvertInputTextToSha512(UserTools.ANONYMOUS_USER_NICKNAME), Email = "*****@*****.**", CreateAccountDate = new DateTime(2019, 5, 30).ToString(), LastUpdateAccountDate = new DateTime(2019, 6, 20).ToString(), LastLoggedAccountDate = new DateTime(2019, 8, 24).ToString(), AvatarId = 1 }, new User { Id = 2, NickName = "robert1234", Password = UserTools.ConvertInputTextToSha512("password123ba8"), Email = "*****@*****.**", CreateAccountDate = new DateTime(2018, 4, 22).ToString(), LastUpdateAccountDate = new DateTime(2019, 2, 21).ToString(), LastLoggedAccountDate = new DateTime(2019, 9, 12).ToString(), AvatarId = 2 }, new User { Id = 3, NickName = "michal854", Password = UserTools.ConvertInputTextToSha512("polska987wrm"), Email = "*****@*****.**", CreateAccountDate = new DateTime(2019, 1, 20).ToString(), LastUpdateAccountDate = new DateTime(2019, 6, 23).ToString(), LastLoggedAccountDate = new DateTime(2019, 6, 28).ToString(), AvatarId = 5 }, new User { Id = 4, NickName = "witek754", Password = UserTools.ConvertInputTextToSha512("witek123abc"), Email = "*****@*****.**", CreateAccountDate = new DateTime(2019, 4, 30).ToString(), LastUpdateAccountDate = new DateTime(2019, 12, 21).ToString(), LastLoggedAccountDate = new DateTime(2019, 12, 28).ToString(), AvatarId = 7 }, new User { Id = 5, NickName = "adam5", Password = UserTools.ConvertInputTextToSha512("adamP12z"), Email = "*****@*****.**", CreateAccountDate = new DateTime(2018, 3, 29).ToString(), LastUpdateAccountDate = new DateTime(2019, 10, 04).ToString(), LastLoggedAccountDate = new DateTime(2019, 12, 10).ToString(), AvatarId = 3 }); }
public bool UpdateUserData(long lUserId, User user, bool bIsChangeAvatar) { User userFromDb = GetUser(lUserId); string userPassword = user.Password; string userNewPasswordString = (userPassword != null) ? UserTools.ConvertInputTextToSha512(userPassword.Trim()) : string.Empty; string userEmailString = (user.Email != null) ? user.Email.Trim() : string.Empty; bool bUpdateUserDb = false; if (userFromDb != null) { bUpdateUserDb = true; if (userNewPasswordString != null && userNewPasswordString.Length > 0 && userNewPasswordString != userFromDb.Password) { userFromDb.Password = userNewPasswordString; userFromDb.LastUpdateAccountDate = DateTime.Now.ToString(); } if (userEmailString != null && userEmailString.Length > 0 && userEmailString != userFromDb.Email) { userFromDb.Email = userEmailString; } if (bIsChangeAvatar && user.AvatarId > -1 && userFromDb.AvatarId != user.AvatarId) { userFromDb.AvatarId = user.AvatarId; } Update(userFromDb); } return(bUpdateUserDb); }