示例#1
0
        /// <summary>
        /// Authenticate the user and return the user's database entity.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        UserEntity GetAuthenticatedIdentity(String username, String password)
        {
            UserEntity user = UsersDataProvider.ReadByUsername(username);

            if (user != null)
            {
                if (user.Status_Type != Database.Layers.users.UserEnums.eStatusType.Active)
                {
                    throw new InvalidAuthenticationException($"User is not active!");
                }

                UserEntity userAuthorization = UsersDataProvider.ReadAuthorization(user.ID);

                if (userAuthorization.Password != null && !String.IsNullOrEmpty(userAuthorization.Password.Password))
                {
                    Boolean passwordIsValid = Cryptography.VerifyHash(password, userAuthorization.Password.Password);

                    if (passwordIsValid)
                    {
                        return(userAuthorization);
                    }

                    throw new InvalidAuthenticationException($"Invalid password!");
                }
                else
                {
                    throw new InvalidAuthenticationException($"User does not have an active password!");
                }
            }
            else
            {
                throw new IdentityNotFoundException("User not found!", username);
            }
        }
        public void SetUp()
        {
            var userProvider  = new UsersDataProvider(_connection);
            var scoreProvider = new ScoreDataProvider(_connection);

            _scoreService = new ScoreService(scoreProvider, userProvider);
        }
示例#3
0
        static void Main(string[] args)
        {
            var userProvider  = new UsersDataProvider(_connection);
            var scoreProvider = new ScoreDataProvider(_connection);
            var scoreService  = new ScoreService(scoreProvider, userProvider);

            Stopwatch watch = new Stopwatch();

            watch.Start();



            for (int i = 0; i < 100; i++)
            {
                scoreService.AddScore($"Player_{i}", $"Victim_{i}", getRandWeapon(), getRandBodyPart()).Wait();
                for (int j = 0; j < 10 + i; j++)
                {
                    scoreService.AddSuicide("Nub").Wait();
                    scoreService.AddTeamKill($"Player_{i}", $"Victim_{i}", getRandWeapon(), getRandBodyPart()).Wait();
                    scoreService.AddSpawnKill($"Player_{i}", $"Victim_{i}", getRandWeapon(), getRandBodyPart()).Wait();
                }
            }



            watch.Stop();

            Console.WriteLine($"Done\nTime elapsed: {watch.Elapsed}");
            Console.Read();
        }
示例#4
0
        /// <summary>
        /// Loguser in.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ClaimsPrincipal Generate(String username, String password)
        {
            try
            {
                UserEntity user = GetAuthenticatedIdentity(username, password);

                if (user != null)
                {
                    ClaimsPrincipal identityPrincipal = GenerateIdentity(user);
                    UsersDataProvider.UpdateLastLoginTime(user.ID, DateTime.Now);
                    return(identityPrincipal);
                }

                return(null);
            }
            catch (Exception exception)
            {
                throw new InvalidAuthenticationException("Invalid login credentials!", exception);
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            CryptographyProvider hasher = new CryptographyProvider();

            //String result1 = hasher.CreateHash("Pa$$word1");

            //var isVerified = hasher.VerifyHash("Pa$$word1", result1);

            IUsersDataProvider  usersDataProvider = new UsersDataProvider("Server=JOSHUAS-ASUS\\SQLEXPRESS;Database=JWieczorek.Apps;Integrated Security=true;");
            UserIdentityHandler identityHandler   = new UserIdentityHandler(usersDataProvider);

            try
            {
                var identity = identityHandler.Generate("SysAdmin", "Pa$$word1");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            Console.WriteLine();
            Console.Read();
        }