public Boolean TrySignUp(String nickname, String password) { IDataBaseAccessService client = SDbService.Get(); if (client.FindUserByNickname(nickname) != null) { return(false); } Guid userId = Guid.NewGuid(); String salt = CSaltGenerator.Instance.GetNewSalt(); CUser user = new CUser { Nickname = nickname, UserId = userId, RegistrationDate = DateTime.UtcNow, Authentication = new CAuthentication() { UserId = userId, Salt = salt, PasswordHash = ComputePasswordHash(password, salt) } }; return(client.AddUser(user)); }
public GamePage(CGameStartModel model) { InitializeComponent(); IDataBaseAccessService client = SDbService.Get(); switch (model.MySideColor) { case EPieceColor.White: WhitePlayerBadge.Content = new PlayerBadgeControl( CAuthenticationStaff.Instance.User.Nickname, client.GetWinRate(CAuthenticationStaff.Instance.User.UserId)); BlackPlayerBadge.Content = new PlayerBadgeControl( client.FindUserById(model.OpponentId).Nickname, client.GetWinRate(model.OpponentId)); break; case EPieceColor.Black: WhitePlayerBadge.Content = new PlayerBadgeControl( client.FindUserById(model.OpponentId).Nickname, client.GetWinRate(model.OpponentId)); BlackPlayerBadge.Content = new PlayerBadgeControl( CAuthenticationStaff.Instance.User.Nickname, client.GetWinRate(CAuthenticationStaff.Instance.User.UserId)); break; default: throw new InvalidEnumArgumentException("Unknown or undefined player side color"); } DataContext = new CGamePageViewModel(model.GameId, model.MySideColor); }
public CUser TryLogIn(String nickname, String password) { IDataBaseAccessService client = SDbService.Get(); CUser user = client.FindRegisteredUser(nickname); if (user == null) { return(null); } if (_onlineUsers.Contains(user.UserId)) { return(null); } if (!ComputePasswordHash(password, user.Authentication.Salt).SequenceEqual(user.Authentication.PasswordHash)) { return(null); } _onlineUsers.Add(user.UserId); user.Authentication = null; return(user); }