示例#1
0
        void Submit(object obj)
        {
            string encryptedString = (obj as PasswordBox).Password;

            string password = EncryptionHelper.Encrypt(encryptedString);

            if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(encryptedString))
            {
                MessageBox.Show("You must enter values for username and password");
                return;
            }
            tblUser newUser = new tblUser();

            newUser.UserName     = UserName;
            newUser.UserPassword = password;

            tblUser userInDb = service.GetUserByUserName(UserName);

            if (userInDb != null)
            {
                MessageBox.Show("Username is taken. Choose another username.");
                return;
            }

            if (!ValidationClass.IsPasswordValid(encryptedString))
            {
                MessageBox.Show("Password is not valid. \nMinimal length must be 6\n" +
                                "You need at least 2 upper case letters");
                return;
            }

            service.AddUser(newUser);
            MessageBox.Show("You succesfully created account");
            view.Close();
        }