示例#1
0
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            using (var db = new QLBHDataContext())
            {
                var user = db.Users.SingleOrDefault(u => u.f_Username.Equals(textBoxUsername.Text));

                if (user != null)
                {
                    EncryptPassword encryptPw = new EncryptPassword();

                    if (encryptPw.IsPasswordValid(textBoxPassword.Text, user.f_Password))
                    {
                        MessageBox.Show("Logged in successfully!");
                    }
                    else
                    {
                        MessageBox.Show("Login failed!");
                    }
                }
                else
                {
                    MessageBox.Show("Login failed!");
                }
            }
        }
示例#2
0
        /// <summary>
        /// Get user from UI
        /// </summary>
        /// <returns></returns>
        private User GetUser()
        {
            EncryptPassword encryptPw = new EncryptPassword();

            return(new User
            {
                f_Username = textBoxUsername.Text,
                f_Password = encryptPw.GetSaltedPassword(textBoxPassword.Text),
                f_Name = textBoxName.Text,
                f_Email = textBoxEmail.Text,
                f_DOB = DateTime.ParseExact(textBoxDateOfBirth.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture),
                f_Permission = 0
            });
        }