Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetRandomPassword(int length = 10)
        {
            if (length < 8)
            {
                throw new ArgumentException("Password must be at least 8 characters.", nameof(length));
            }

            string password = string.Empty;

            password += CharHelpers.GetRandomLowercaseCharacter();
            password += CharHelpers.GetRandomUppercaseCharacter();
            password += CharHelpers.GetRandomSpecialCharacter();
            password += IntHelpers.GetRandomNumber(0, 9);

            for (int i = 4; i < length; i++)
            {
                password += CharHelpers.GetRandomCharacter();
            }

            password = ReplaceDuplicateCharacters(password);

            password = password.Randomize().Randomize();

            return(password);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a random character
        /// </summary>
        /// <returns></returns>
        public static char GetRandomCharacter()
        {
            var chars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!§$%&/()=_?#1234567890";

            var randomNumber = IntHelpers.GetRandomNumber(chars.Length);

            return(chars[randomNumber]);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a random lowercase character
        /// </summary>
        /// <returns></returns>
        public static char GetRandomSpecialCharacter()
        {
            var chars = @"!§$%&/()=_?#";

            var randomNumber = IntHelpers.GetRandomNumber(chars.Length);

            return(chars[randomNumber]);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a random lowercase character
        /// </summary>
        /// <returns></returns>
        public static char GetRandomLowercaseCharacter()
        {
            var chars = @"abcdefghijklmnopqrstuvwxyz";

            var randomNumber = IntHelpers.GetRandomNumber(chars.Length);

            return(chars[randomNumber]);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a random uppercase character
        /// </summary>
        /// <returns></returns>
        public static char GetRandomUppercaseCharacter()
        {
            var chars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var randomNumber = IntHelpers.GetRandomNumber(chars.Length);

            return(chars[randomNumber]);
        }