예제 #1
0
파일: Test.cs 프로젝트: stormsw/spassgen
 public void TestCasePasswordMinCharsByRules2()
 {
     PasswordBuilder pb = new PasswordBuilder ();
     pb.AddChunk (new Chunk (){ Alpha = "a", Min=2 });
     pb.AddChunk (new Chunk (){ Alpha = "b", Min=2 });
     Assert.AreEqual (pb.MinLengthSetByRules, 4);
 }
예제 #2
0
파일: Test.cs 프로젝트: stormsw/spassgen
 public void TestCasePasswordSameChars()
 {
     PasswordBuilder pb = new PasswordBuilder ();
     pb.AddChunk (new Chunk (){ Alpha = "a", Min=1 });
     pb.SetLength (1);
     Assert.AreEqual (pb.Generate (), "a");
 }
예제 #3
0
 public void TestMethod1()
 {
     PasswordBuilder pb = new PasswordBuilder();
     pb.AddChunk(new Chunk() { Alpha = "a", Min = 2 });
     pb.AddChunk(new Chunk() { Alpha = "b", Min = 2 });
     Assert.Equal(pb.MinLengthSetByRules, 4);
 }
예제 #4
0
파일: Test.cs 프로젝트: stormsw/spassgen
 public void TestCasePasswordLength()
 {
     PasswordBuilder pb = new PasswordBuilder ();
     pb.AddChunk (new Chunk (){ Alpha = "a", Min=10 });
     pb.SetLength (1);
     Assert.Catch<AggregateException> (()=>pb.Generate ());
 }
        public ServiceResponse <UserLoginModel> Login([FromBody] UserLoginModel userLoginModel)
        {
            var response = new ServiceResponse <UserLoginModel>();
            var model    = new UserModel()
            {
                UserName = userLoginModel.UserName,
                Password = (new PasswordBuilder()).Encrpyt(userLoginModel.Password)
            };
            var previouslyCreatedUser = _userService.GetValidUser(model.UserName, model.Password).Data;

            if (previouslyCreatedUser == null)
            {
                response.IsSuccessed = false;
                response.Errors      = new List <ServiceError>()
                {
                    new ServiceError()
                    {
                        Code = "100001", Message = "User credential is not valid.", InnerMessage = "User credential is not valid."
                    }
                };
            }
            else
            {
                var newToken = new PasswordBuilder().GenerateToken();
                previouslyCreatedUser.Token = newToken;
                _userService.Update(previouslyCreatedUser);
                response.IsSuccessed     = true;
                userLoginModel.FirstName = previouslyCreatedUser.FirstName;
                userLoginModel.LastName  = previouslyCreatedUser.LastName;
                userLoginModel.Token     = newToken;
                userLoginModel.Password  = string.Empty;
                response.Data            = userLoginModel;
            }
            return(response);
        }
예제 #6
0
        public override void Seed(EntityTypeBuilder <DataUserAccount> context)
        {
            PasswordBuilder pb = new PasswordBuilder();

            context.HasData(new DataUserAccount {
                IsAdmin = true, Name = "Admin", LoginName = "admin", Guid = Guid.NewGuid(), CreatedDateTime = DateTime.Now, PasswordGuid = pb.MakeGuid("admin", "1"), PasswordHash = pb.MakePasswordHash("admin", "1")
            });
        }
예제 #7
0
        /// <summary>
        /// Reads and masks a password from the input.
        /// </summary>
        /// <param name="outputChar">The character to output instead.</param>
        /// <param name="maxLength">The maximum length of the password.</param>
        /// <returns>The password as <see cref="string"/>.</returns>
        public static string ReadPassword(char outputChar, int maxLength)
        {
            PasswordBuilder passwordBuilder = new PasswordBuilder();
            string          result          = ReadPasswordInternal(outputChar, maxLength, passwordBuilder);

            Console.WriteLine();
            return(result);
        }
        public async Task <IAccessToken> GetTokenByPinCode(string pinCode, string cellular, string email)
        {
            PasswordBuilder pwd = new PasswordBuilder();

            IAccessToken accessToken = await m_session_repository.GetTokenByPinCode(pwd.MakeGuid(cellular, email, pinCode), pwd.MakePasswordHash(cellular, email, pinCode), pwd);

            if (accessToken == null)
            {
                return(default);
예제 #9
0
 private void initializePasswordBuilder()
 {
     builder = new PasswordBuilder();
     builder.SetLength(12);
     bool addDeafultRules = true;
     password = builder.
         AddConditional<SpecialChars>(addDeafultRules, 2).
         AddConditional<Numerals>(addDeafultRules, 4).
         AddConditional<LowAlpha>(addDeafultRules, 3).
         AddConditional<CapsAlpha>(addDeafultRules, 2).Generate();
 }
예제 #10
0
        private void initializePasswordBuilder()
        {
            builder = new PasswordBuilder();
            builder.SetLength(12);
            bool addDeafultRules = true;

            password = builder.
                       AddConditional <SpecialChars>(addDeafultRules, 2).
                       AddConditional <Numerals>(addDeafultRules, 4).
                       AddConditional <LowAlpha>(addDeafultRules, 3).
                       AddConditional <CapsAlpha>(addDeafultRules, 2).Generate();
        }
예제 #11
0
        public MainForm()
        {
            InitializeComponent();

            _builder = new PasswordBuilder();
            _characterSetComboBox.DataSource = new ICharacterSet[] { new Alphabet(),
                                                                     new Alphanumeric(),
                                                                     new AlphanumericSymbols(),
                                                                     new AlphanumericSymbolsSpace() };
            _characterSetComboBox.DisplayMember = "Name";
            _characterSetComboBox.ValueMember   = "CharacterSet";
            _characterSetComboBox.SelectedIndex = 2;
        }
예제 #12
0
        public async Task <string> GeneratePinCode(IUserAccount user, string cellular, string email)
        {
            IAccessToken accessToken = await GenerateToken(user);

            PasswordBuilder  pb  = new PasswordBuilder();
            PinCodeGenerator gen = new PinCodeGenerator();

            string pinCode = gen.GenerateNextPinCode();

            await m_session_repository.ResetPinCode(accessToken.Guid, pb.MakeGuid(cellular, email, pinCode), pb.MakePasswordHash(cellular, email, pinCode));

            return(pinCode);
        }
예제 #13
0
        public async Task <bool> ResetPasspord(IAccessToken accessToken, string newPassword, string confirmPassword)
        {
            if (string.CompareOrdinal(newPassword, confirmPassword) == 0)
            {
                if (accessToken != null && !accessToken.HasExpired)
                {
                    PasswordBuilder pb = new PasswordBuilder();
                    await m_user_repository.ResetPassword(accessToken.User.Guid, pb.MakeGuid(accessToken.User.LoginName, newPassword), pb.MakePasswordHash(accessToken.User.LoginName, newPassword));

                    return(true);
                }
            }

            return(false);
        }
예제 #14
0
 public PasswordProvider()
 {
     validator = new PasswordParametersValidator();
     builder   = new PasswordBuilder();
 }
예제 #15
0
파일: Program.cs 프로젝트: stormsw/spassgen
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        static void Main(string[] args)
        {
            // for examples look here: http://fclp.github.io/fluent-command-line-parser/
            var p = new FluentCommandLineParser ();
            var builder = new PasswordBuilder ();

            p.SetupHelp("?", "help").Callback(text => Console.WriteLine(text));
            /*
            p.Setup<int>('n',"minimal")
             .Callback(min => builder.SetMinimalLength(min))
             .SetDefault(8);

            p.Setup<int>('m')
             .Callback(value => builder.SetMaxLength( value))
             .SetDefault(8); //Can be Required()
            */
            p.Setup<int> ('l', "length")
             .Callback (value => builder.SetLength (value))
             .SetDefault (8).WithDescription("Set password length."); //Can be Required()

            /*
            int alphaLength = 1;

            p.Setup<int>('c', "alfa-length")
             .Callback(value => builder.SetLength(value))
             .SetDefault(8); //Can be Required()*/

            p.Setup<bool> ('s', "special")
             .Callback (silent => builder.AddConditional<SpecialChars> (silent, 1))
             .SetDefault (false).WithDescription(string.Format("Use special: {0}",new SpecialChars().Alpha));

            p.Setup<bool> ('d', "digits")
             .Callback (silent => builder.AddConditional<Numerals> (silent, 1))
             .SetDefault(false).WithDescription(string.Format("Use numeric characters: {0}", new Numerals().Alpha));

            p.Setup<bool> ('a', "small-chars")
             .Callback (silent => builder.AddConditional<LowAlpha> (silent, 1))
             .SetDefault(false).WithDescription(string.Format("Use low alpha: {0}", new LowAlpha().Alpha));

            p.Setup<bool> ('z', "caps-chars")
             .Callback (silent => builder.AddConditional<CapsAlpha> (silent, 1))
             .SetDefault(false).WithDescription(string.Format("Use capitals: {0}", new CapsAlpha().Alpha));

            p.Setup<string>('x', "custom")
             .Callback(value => builder.AddChunk(new Chunk(){Alpha=value,Min=1}))
             .WithDescription("Use custom charset");

            p.Parse (args);

            try
            {
                string password = builder.Generate ();
                Console.WriteLine (password);
            }
            // TODO: use special PasswordBuilder exception there
            catch (AggregateException e)
            {
                foreach (var ex in e.InnerExceptions)
                {
                    Console.WriteLine(ex.Message);
                    if (ex is ArgumentException) {
                        Console.WriteLine ("The parameters is invalid, processing is stopped.");
                    }
                }
            }
        }