예제 #1
0
        private async void btnReset_Click(object sender, EventArgs e)
        {
            if(txtPassword.Text != txtPasswordRepeat.Text)
            {
                MessageBox.Show(
                    "The passwords specified don't match. Please try again.",
                    "Passwords don't match",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                txtPassword.Clear();
                txtPasswordRepeat.Clear();
                txtPassword.Focus();
                return;
            }
            if(txtPassword.Text.Length < 5 &&
                txtPassword.Text.Length > 50)
            {
                MessageBox.Show(
                    "The password size is invalid, please use a password between 5 and 50 characters long.",
                    "Password size invalid",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                txtPassword.Clear();
                txtPasswordRepeat.Clear();
                txtPassword.Focus();
                return;
            }

            using(var ctx = new DataContext())
            {
                var user = ctx.XUsers.Single(u => u.Username == this.username);

                user.Password = Convert.ToBase64String(new HMACSHA256(Encoding.Unicode.GetBytes(txtPassword.Text))
                    .ComputeHash(Encoding.Unicode.GetBytes(this.username)));

                ctx.XUsers.Attach(user);
                ctx.Entry<XUser>(user).Property(p => p.Password).IsModified = true;
                await ctx.SaveChangesAsync();
            }
            this.Close();
        }
예제 #2
0
        private void CommitSetting(DataContext ctx, string key, string value)
        {
            var setting = ctx.Settings.SingleOrDefault(s => s.Key == key);
            if (setting != null)
            {
                setting.Value = value;

                ctx.Settings.Attach(setting);
                ctx.Entry<Setting>(setting).Property(p => p.Value).IsModified = true;
            }
            else
                ctx.Settings.Add(new Setting()
                {
                    Key = key,
                    Value = value
                });
        }