Esempio n. 1
0
        public bool Validate(bool forRegister)
        {
            ErrorMessage = "";

            if (forRegister)
            {
                if (string.IsNullOrEmpty(RepeatPassword) || RepeatPassword != Password)
                {
                    ErrorMessage = "Passwords do not match";
                }
            }

            if (string.IsNullOrEmpty(Password) || Password.Length < 6)
            {
                ErrorMessage = "Password require minimum 6 characters";
            }
            else if (Password.Contains(" "))
            {
                ErrorMessage = "Password cannot include any empty space";
            }

            if (string.IsNullOrEmpty(Email))
            {
                ErrorMessage = "Enter your email";
            }
            else if (Email.Length < 5 || !Email.Contains("@") || !Email.Contains("."))
            {
                ErrorMessage = "Invalid email adress";
            }

            return(string.IsNullOrEmpty(ErrorMessage));
        }
Esempio n. 2
0
        /// <summary>
        /// Get a Redis configuration object for use with StackExchange.Redis
        /// </summary>
        /// <param name="optionsType">Expects StackExchange.Redis.ConfigurationOptions</param>
        /// <returns>This object typed as ConfigurationOptions</returns>
        /// <remarks>Includes comma in password detection and workaround for https://github.com/SteeltoeOSS/Connectors/issues/10 </remarks>
        public object ToStackExchangeObject(Type optionsType)
        {
            var stackObject = Activator.CreateInstance(optionsType);

            // to remove this comma workaround, follow up on https://github.com/StackExchange/StackExchange.Redis/issues/680
            var tempPassword  = Password;
            var resetPassword = false;

            if (Password?.Contains(",") == true)
            {
                Password      = string.Empty;
                resetPassword = true;
            }

            // this return is effectively "StackExchange.Redis.ConfigurationOptions.Parse(this.ToString())"
            var config = optionsType.GetMethod("Parse", new Type[] { typeof(string) })
                         .Invoke(stackObject, new object[] { ToString() });

            if (resetPassword)
            {
                ReflectionHelpers.TrySetProperty(config, "Password", tempPassword);
            }

            return(config);
        }
Esempio n. 3
0
        public void AskAboutLetter(IChatClient chatClient, string letterToAsk, ChatUser chatUser)
        {
            if (!IsRunning)
            {
                SendGameNotStartedMessage(chatClient, chatUser);
                return;
            }

            if (_guessedLetters.Any(g => g.Letter == letterToAsk))
            {
                chatClient.SendMessage($"{letterToAsk} has already been guessed, {chatUser.DisplayName}.");
                return;
            }

            _guessedLetters.Add(new HangmanGuess(letterToAsk, chatUser));
            if (Password.Contains(letterToAsk))
            {
                if (Password == MaskedPassword)
                {
                    GuessWord(chatClient, MaskedPassword, chatUser);
                    return;
                }

                chatClient.SendMessage($"Yep, {letterToAsk} is in here. {MaskedPassword}");
            }
            else
            {
                chatClient.SendMessage($"No, {letterToAsk} is not in the word.");
                CheckForGameLost(chatClient);
            }
        }
Esempio n. 4
0
        public Tuple <bool, string> IsValidPassword()
        {
            TextBlock.Visibility = Visibility.Visible;

            if (Password.Contains(" "))
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password cannot contain white spaces."));
            }

            if (!Password.Any(char.IsNumber))
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password must contain at least one numeric char."));
            }

            // perhaps the requirements meant to be 1 capital letter?
            //if (password.Count(char.IsUpper) != 1)
            if (!Password.Any(char.IsUpper))
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password must contain at least 1 capital letter."));
            }

            if (Password.Length < 8)
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password is too short, must be\n at least 8 characters."));
            }

            return(new Tuple <bool, string>(true, TextBlock.Text = string.Empty));
        }
Esempio n. 5
0
 private void CheckForGameLost(IChatClient chatClient)
 {
     if (_guessedLetters.Count(x => !Password.Contains(x.Letter)) > 5)
     {
         chatClient.SendMessage("That's too many failed guesses. You all lost. devchaFail ");
         ResetGame();
     }
 }
Esempio n. 6
0
 private void ProceedCommandAction()
 {
     if (Password.Contains(";"))
     {
         ErrorMessage = "Password cannot contain semicolon ';' character";
         return;
     }
     if (Registering)
     {
         MakeApiCallAsync(() =>
         {
             var userId = _userService.Register(Password);
             if (userId != 0)
             {
                 _storageService.SaveUser(new UserItem {
                     Id = userId, KeyPair = _encryptionService.GenerateKeyPair()
                 });
             }
             return(userId);
         }, ret =>
         {
             if (ret != 0)
             {
                 ShowViewModel <RegistrationViewModel>();
             }
             else
             {
                 ErrorMessage = "Oops! Someone already registered with this device";
             }
         });
     }
     else
     {
         MakeApiCallAsync(() =>
         {
             var loggedIn = _userService.Login(Password);
             if (loggedIn)
             {
                 _messageService.FetchMessages();
                 _messageService.FetchContacts();
             }
             return(loggedIn);
         }, b =>
         {
             if (b)
             {
                 InitSynchronizationTasks();
                 ShowViewModel <HomeViewModel>();
             }
             else
             {
                 ErrorMessage = "Invalid password";
             }
         });
     }
 }
Esempio n. 7
0
 private void CheckForGameLost(IChatClient chatClient)
 {
     if (_guessedLetters.Count(x => !Password.Contains(x.Letter)) > 5)
     {
         chatClient.SendMessage(
             $"That's too many failed guesses. You all lost. devchaFail. The word was: {Password}");
         ResetGame();
         _hangmanDisplayNotification.HangmanLose();
     }
 }
Esempio n. 8
0
 private bool CheckPassword(string password)
 {
     if (Password.Contains(" "))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Esempio n. 9
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     //TODO 正则表达式验证用户名密码是否合法
     if (Account.Contains("'"))
     {
         yield return(new ValidationResult("账号验证不合法", new[] { nameof(Account) }));
     }
     if (Password.Contains("'"))
     {
         yield return(new ValidationResult("密码验证不合法", new[] { nameof(Account) }));
     }
 }
Esempio n. 10
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> results = new List <ValidationResult>();

            if (Password.Contains(Login))
            {
                results.Add(new ValidationResult("Hasło nie może zawierać loginu.", new List <string> {
                    "Password"
                }));
            }

            return(results);
        }
Esempio n. 11
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            string number      = "Not Contain Number";
            string upperLetter = "Not Contain Uppercase Letter";

            if (Password.Contains("0") || Password.Contains("1") || Password.Contains("2") || Password.Contains("3") || Password.Contains("4") || Password.Contains("5") || Password.Contains("6") || Password.Contains("7") || Password.Contains("8") || Password.Contains("9"))
            {
                number = "";
            }
            bool hasUppercase = !Password.Equals(Password.ToLower());

            if (hasUppercase)
            {
                upperLetter = "";
            }
            Console.WriteLine("NUMBER: " + number);
            Console.WriteLine("UPPERLETTER: " + upperLetter);
            if (!number.Equals("") || !upperLetter.Equals(""))
            {
                yield return(new ValidationResult("Your password is incorrect because: " + number + " " + upperLetter, new[] { "Password" }));
            }
        }
Esempio n. 12
0
        public void AskAboutLetter(IChatClient chatClient, string letterToAsk, ChatUser chatUser)
        {
            if (!IsRunning)
            {
                SendGameNotStartedMessage(chatClient, chatUser);
                return;
            }

            if (_guessedLetters.Any(g => g.Letter == letterToAsk))
            {
                chatClient.SendMessage($"{letterToAsk} has already been guessed, {chatUser.DisplayName}.");
                return;
            }

            if (!ALL_LETTERS.Contains(letterToAsk))
            {
                chatClient.SendMessage($"Sorry, {letterToAsk} is not an A-Z character. Please try again.");
                return;
            }

            _guessedLetters.Add(new HangmanGuess(letterToAsk, chatUser));
            SendAllGuessedLetters();
            if (Password.Contains(letterToAsk))
            {
                if (Password == MaskedPassword)
                {
                    GuessWord(chatClient, MaskedPassword, chatUser);
                    return;
                }

                chatClient.SendMessage($"Yep, {letterToAsk} is in here. {MaskedPassword}");
            }
            else
            {
                chatClient.SendMessage($"No, {letterToAsk} is not in the word.");
                _hangmanDisplayNotification.HangmanWrongAnswer();
                CheckForGameLost(chatClient);
            }
        }
        public void RegistrationButton(object sender)
        {
            bool alreadyExists = Users.Any(x => x.USER1 == User);

            if ((User == " " || User == null || User.Contains(" ") || User.Length > 20 || User.Length <= 8) || (Password == " " || Password == null || Password.Contains(" ") || Password.Length < 6 || Password.Length > 20))
            {
                MessageBox.Show("Wrong username or password format!");
            }
            else if (alreadyExists)
            {
                MessageBox.Show("User already exist!");
            }
            else
            {
                addNewOwner();
                addNewUser();
                MessageBox.Show("Registration successfull");
            }
        }
        async Task <bool> DoRegistration()
        {
            ActivationMessage = "";
            ErrorMessage      = "";
            ShowLoginError    = false;

            if (!CheckEmailAddressValid(EmailAddress))
            {
                ShowLoginError = true;
                ErrorMessage   = "You need to enter a valid email address.";
                return(false);
            }

            if (Password.Length < 10)
            {
                ShowLoginError = true;
                ErrorMessage   = "Password must be at least 10 characters.";
                return(false);
            }

            if (Password.Contains("\""))
            {
                ShowLoginError = true;
                ErrorMessage   = "Password cannot contain a \".";
                return(false);
            }

            UserRegistrationRequest user = new UserRegistrationRequest();

            user.AllowEmail      = AllowEmail;
            user.Username        = Username;
            user.Password        = Password;
            user.ConfirmPassword = PasswordConfirm;
            user.FirstName       = FirstName;
            user.LastName        = LastName;
            user.Company         = Company;
            user.Email           = EmailAddress;
            user.Password        = Password;
            user.UserType        = databaseUse;

            ShowBusy = true;
            try
            {
                var resp = await AltiumDbApi.AccountRegister(user);

                ShowBusy = false;

                if (resp.Success)
                {
                    ActivationCode        = "";
                    ActivationMessage     = "Registration complete. Please activate with the code you were emailed - it may take a few minutes to arrive.";
                    ShowActivationMessage = true;
                    ShowActivationBox     = true;
                }
                else
                {
                    ShowLoginError = true;
                    ErrorMessage   = resp.Message;
                    return(false);
                }
            }
            catch (Exception err)
            {
                ShowBusy = false;

                ShowLoginError = true;
                ErrorMessage   = err.InnerException.Message;
                return(false);
            }

            return(true);
        }
Esempio n. 15
0
        public async Task Register()
        {
            if (string.IsNullOrWhiteSpace(Mail) || !Mail.Contains("@") || !Mail.Contains(".") || !Mail.Contains("com"))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please enter a valid mail address!", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(FirstName) || FirstName.Length < 4)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "The 'fist name' field requires 4 letters", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(LastName) || LastName.Length < 4)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "The 'last name' field requires 4 letters", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(Address) || Address.Length < 5)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "The 'address' field requires 5 letters", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(ImageLink) || !ImageLink.Contains(".jpg"))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please enter an image link with the '.jpg' extension", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(PhoneNumber) || PhoneNumber.Length < 9)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please enter a valid phone number", "OK");

                return;
            }

            if (!string.IsNullOrWhiteSpace(PhoneNumber))
            {
                string pattern = @"\(?\d{3}\)?-? ?/*\d{3}-? *-?\d{3}";
                Regex  reg     = new Regex(pattern);
                if (!reg.IsMatch(PhoneNumber))
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Phone number: xxx / xxx - xxx", "OK");

                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(Username) || Username.Length < 4 || Username.Length > 50)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Username length: 4-50", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(Password) || Password.Length < 4 || Password.Length > 50)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Password length: 4-50", "OK");

                return;
            }

            if (!string.IsNullOrWhiteSpace(Password) && Password.Contains(" "))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Password can't contain spaces", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(ConfirmPassword) || ConfirmPassword.Length < 4 || ConfirmPassword.Length > 50)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Confirmation length: 4-50", "OK");

                return;
            }

            if (!string.IsNullOrWhiteSpace(ConfirmPassword) && ConfirmPassword.Contains(" "))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Confirmation can't contain spaces", "OK");

                return;
            }

            if (Password != ConfirmPassword)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Passwords don't match!", "OK");

                return;
            }

            Model.Requests.InsertUserRequest request = new Model.Requests.InsertUserRequest()
            {
                Mail            = Mail,
                Address         = Address,
                BirthDate       = BirthDate,
                ConfirmPassword = ConfirmPassword,
                Password        = Password,
                FirstName       = FirstName,
                ImageLink       = ImageLink,
                LastName        = LastName,
                PhoneNumber     = PhoneNumber,
                Username        = Username
            };

            try {
                var User = await _apiService.Insert <Model.User>(request);

                APIService.Username          = Username;
                APIService.Password          = Password;
                APIService.User              = User;
                Application.Current.MainPage = new MainPage();
                await Application.Current.MainPage.DisplayAlert("Welcome", "Enjoy your stay at Watchables!", "OK");
            }
            catch {
                await Application.Current.MainPage.DisplayAlert("Error", "The username is already taken!", "OK");

                return;
            }
        }