Exemple #1
0
 public static void CreateAccount(bool agree, string username, string password, string name, string surname, string address)
 {
     if (!agree)
     {
         NotificationWindowContoller.NewNotification("Error!", "You can't create new account", ComputerPeripheralsShop.Models.Notification.NotificationType.Success);
         return;
     }
     using (UnitOfWork context = new UnitOfWork())
     {
         foreach (User curUser in context.UserRepository.AppContext.User)
         {
             if (username.Equals(curUser.Login))
             {
                 NotificationWindowContoller.NewNotification("Error!", "This username already exists", ComputerPeripheralsShop.Models.Notification.NotificationType.Danger);
                 return;
             }
         }
         User user = new User(username, HashConverters.GetHashEncryption(password), name, surname, address);
         context.UserRepository.AppContext.User.Add(user);
         context.SaveChanges();
         curUser    = user;
         IsLoggedIn = true;
         CloseCreateAccountWindow();
     }
 }
Exemple #2
0
        public static void Login(string username, string password)
        {
            using (UnitOfWork context = new UnitOfWork())
            {
                var registeredUser = context.UserRepository.GetUserByUsername(username);
                if (registeredUser != null)
                {
                    if (HashConverters.GetHashString(HashConverters.GetHashEncryption(password)).Equals(HashConverters.GetHashString(registeredUser.Password_hash)))
                    {
                        curUser    = registeredUser;
                        IsLoggedIn = true;
                        CloseLoginWindow();
                        return;
                    }
                }

                NotificationWindowContoller.NewNotification("Error!", "The username or password is incorrect", ComputerPeripheralsShop.Models.Notification.NotificationType.Danger);
            }
        }