コード例 #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //create salt
            byte[] salt;
            new RNGCryptoServiceProvider().GetBytes(salt = new byte[SaltSize]);
            //generate hash with salt
            string hash = PasswordHashHelper.Hash(txtPassword.Text, salt, 1000);

            var checkLogin = from cc_users in db.cc_users
                             where cc_users.UserName == txtusername.Text
                             select new
            {
                username = cc_users.UserName,
                password = cc_users.Password,
                salt     = cc_users.Salt
            };

            foreach (var user in checkLogin)
            {
                //var saltByte = new byte[user.salt.Length];
                if (PasswordHashHelper.Verify(txtPassword.Text, user.password))
                {
                    //MessageBox.Show("Passwords Match");
                    Properties.Settings.Default.Username = txtusername.Text;
                    Properties.Settings.Default.Save();
                    Dashboard dashboard = new Dashboard();
                    dashboard.Show();
                }
                else

                {
                    MessageBox.Show("Login failed");
                }
            }
        }
コード例 #2
0
        public bool VerifyPassword(string hash, string password, bool isDefault)
        {
            if (isDefault)
            {
                return(hash == password);
            }

            return(PasswordHashHelper.Verify(password, hash));
        }
コード例 #3
0
        public long?SessionId => null;  //TODO

        public bool VerifyPassword(string hash, string password, bool isDefault)
        {
            if (isDefault)
            {
                throw new InvalidOperationException("Not accessible with default password");
            }

            return(PasswordHashHelper.Verify(password, hash));
        }
コード例 #4
0
        public async Task <bool> Login(LoginRequest loginRequest)
        {
            var context = new DynamoDBContext(_dynamoClient);

            var scanConditions = new List <ScanCondition>
            {
                new ScanCondition("Email", ScanOperator.Equal, new object[] { loginRequest.Email })
            };
            var config = new DynamoDBOperationConfig()
            {
                OverrideTableName = DynamoConstants.CREDENTIALS_TABLE
            };

            var passwordResponse = await context.ScanAsync <PasswordEntryDynamo>(scanConditions, config).GetRemainingAsync();

            if (passwordResponse.Count == 0)
            {
                throw new InvalidEmailOrPasswordException();
            }
            return(PasswordHashHelper.Verify(passwordResponse[0].PasswordHash, loginRequest.Password));
        }
コード例 #5
0
        public static void Login()
        {
            Linq.dbStructureDataContext db = new Linq.dbStructureDataContext();
            Form1 frm = new Form1();

            //create salt
            byte[] salt;
            new RNGCryptoServiceProvider().GetBytes(salt = new byte[SaltSize]);
            //generate hash with salt
            string hash = PasswordHashHelper.Hash(frm.txtNewPass.Text, salt, 1000);

            var checkLogin = from cc_users in db.cc_users
                             where cc_users.UserName == frm.txtLoginUser.Text
                             select new
            {
                username = cc_users.UserName,
                password = cc_users.Password,
                salt     = cc_users.Salt
            };

            foreach (var user in checkLogin)
            {
                //var saltByte = new byte[user.salt.Length];
                if (PasswordHashHelper.Verify(frm.txtLoginPass.Text, user.password))
                {
                    //MessageBox.Show("Passwords Match");
                    Properties.Settings.Default.Username = frm.txtLoginUser.Text;
                    Properties.Settings.Default.Save();
                    Dashboard dashboard = new Dashboard();
                    dashboard.Show();
                }
                else

                {
                    MessageBox.Show("Login failed");
                }
            }
        }