Exemple #1
0
        public async Task <SessionDto> LogIn(LogInForm logInForm)
        {
            string   salt           = Guid.NewGuid().ToString();
            string   passwordSalted = Hasher.GetHash(Hasher.GetHash(logInForm.Password) + salt);
            LogInDto dto            = new LogInDto(logInForm.Login, passwordSalted, salt);

            Session = await Server.SendPost <LogInDto, SessionDto>(
                ServerHolder.SERVER_URL + LOG_IN_ENDPOINT, dto
                );

            return(Session);
        }
Exemple #2
0
        private bool checkCredentials(UserDTO user)
        {
            using (MySqlConnection connection = ConnectionManager.getConnection())
            {
                string       queryString = "SELECT EXISTS(SELECT id FROM `Users` WHERE username=@username AND password=@password)";
                MySqlCommand command     = new MySqlCommand(queryString, connection);

                MySqlParameter usernameParam = new MySqlParameter("@username", SqlDbType.VarChar);
                usernameParam.Value = user.username;
                command.Parameters.Add(usernameParam);

                MySqlParameter passwordParam = new MySqlParameter("@password", SqlDbType.VarChar);
                passwordParam.Value = HashingService.GetHash(user.password);
                command.Parameters.Add(passwordParam);

                command.Connection.Open();
                return(command.ExecuteScalar().ToString().Equals("1"));
            }
        }
Exemple #3
0
        private void createUser(UserDTO user)
        {
            using (MySqlConnection connection = ConnectionManager.getConnection())
            {
                string       queryString = "INSERT INTO `Users`(username, password) VALUES(@username, @password)";
                MySqlCommand command     = new MySqlCommand(queryString, connection);

                MySqlParameter usernameParam = new MySqlParameter("@username", MySqlDbType.VarChar);
                usernameParam.Value = user.username;
                command.Parameters.Add(usernameParam);

                MySqlParameter passwordParam = new MySqlParameter("@password", MySqlDbType.VarChar);
                passwordParam.Value = HashingService.GetHash(user.password);
                command.Parameters.Add(passwordParam);

                command.Connection.Open();
                command.ExecuteNonQuery();
            }
        }