Exemple #1
0
        private bool CheckUserInfo(string checkLogin, string checkPassword)
        {
            bool check = false;

            var provider = new SHA1CryptoServiceProvider();

            byte[] bytes = Encoding.UTF8.GetBytes(checkPassword);
            string hashedPasswordFromForm = Convert.ToBase64String(provider.ComputeHash(bytes));

            using (ExamDatabase tsd = new ExamDatabase())
            {
                var user = tsd.Users.FirstOrDefault(u => u.Login == checkLogin);

                bytes = Encoding.UTF8.GetBytes(user.Password);
                string hashedPassworfFromDb = Convert.ToBase64String(provider.ComputeHash(bytes));

                if (user != null && hashedPassworfFromDb == hashedPasswordFromForm)
                {
                    IsAdmin = user.IsAdmin;
                    check   = true;
                }
            }

            return(check);
        }
Exemple #2
0
        //REGION
        #region Register Button

        public void RegisterBtn_Click(object sender, RoutedEventArgs e)
        {
            //var provider = new SHA1CryptoServiceProvider();
            //byte[] bytes = Encoding.UTF8.GetBytes(_instance.PasswordTb.Password);
            //string hashedPassword = Convert.ToBase64String(provider.ComputeHash(bytes));

            try
            {
                Users user = new Users()
                {
                    Login = _instance.LogTb.Text, Password = _instance.PasswordTb.Password
                };
                using (ExamDatabase ud = new ExamDatabase())
                {
                    ud.Users.Add(user);
                    ud.SaveChanges();
                }
                MessageBox.Show("U've been registered");
            }

            catch
            {
                MessageBox.Show("Incorrect log or password");
            }
        }