public void CanRegistrateUserWithWrongPassword()
        {
            var registration = new UserActions();
            //password is too short
            try
            {
                var user = new PreRegistrateUser
                    {
                        Login = "******",
                        Password = "******",
                        ConfirmPassword = "******",
                        Email = "*****@*****.**",
                        Info = "dsfsdfsdf"
                    };
                registration.TryRegistrateUser(user);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), typeof(PasswordIncorrectedException));
            }
            finally
            {

                //password too long
                try
                {
                    var user = new PreRegistrateUser
                        {
                            Login = "******",
                            Password = "******",
                            ConfirmPassword = "******",
                            Email = "*****@*****.**",
                            Info = "dsfsdfsdf"
                        };
                    registration.TryRegistrateUser(user);
                }
                catch (Exception ex)
                {
                    Assert.AreEqual(ex.GetType(), typeof(PasswordIncorrectedException));
                }
                finally
                {
                    //password doesn't include number
                    try
                    {
                        var user = new PreRegistrateUser
                            {
                                Login = "******",
                                Password = "******",
                                ConfirmPassword = "******",
                                Email = "*****@*****.**",
                                Info = "dsfsdfsdf"
                            };
                        registration.TryRegistrateUser(user);
                    }
                    catch (Exception ex)
                    {
                        Assert.AreEqual(ex.GetType(), typeof(PasswordIncorrectedException));
                    }
                    //password includes some wrong numbers
                    finally
                    {
                        try
                        {
                            var user = new PreRegistrateUser
                                {
                                    Login = "******",
                                    Password = "******",
                                    ConfirmPassword = "******",
                                    Email = "*****@*****.**",
                                    Info = "dsfsdfsdf"
                                };
                            registration.TryRegistrateUser(user);
                        }
                        catch (Exception ex)
                        {
                            Assert.AreEqual(ex.GetType(), typeof(PasswordIncorrectedException));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void RegistrateUser(PreRegistrateUser user)
 {
     string salt = PasswordActions.GenerateSalt();
     //create user
     var regUser = new User
     {
         CreateDate = DateTime.Now,
         Email = user.Email,
         Info = CorrectInfo(user.Info),
         IsApproved = true,
         Login = user.Login,
         PasswordHash = PasswordActions.GetHashForPassword(user.Password, salt),
         PasswordSalt = salt,
         Role = Roles.SimpleUser,
         UserId = Guid.NewGuid()
     };
     using (var repo = ApplicationSettings.GetRepository())
     {
         repo.CreateUser(regUser);
         repo.SaveChanges();
     }
 }
        public void CanRegistrateUserWithErrorLogin()
        {
            var registration = new UserActions();

            //login is too short
            try
            {
                var user = new PreRegistrateUser
                    {
                        Login = "******",
                        Password = "******",
                        ConfirmPassword = "******",
                        Email = "*****@*****.**",
                        Info = "dsfsdfsdf"
                    };
                registration.TryRegistrateUser(user);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), typeof(LoginIncorrectedException));
            }
            finally
            {
                //login to long
                try
                {
                    var user = new PreRegistrateUser
                        {
                            Login = "******",
                            Password = "******",
                            ConfirmPassword = "******",
                            Email = "*****@*****.**",
                            Info = "dsfsdfsdf"
                        };
                    registration.TryRegistrateUser(user);
                }
                catch (Exception ex)
                {
                    Assert.AreEqual(ex.GetType(), typeof(LoginIncorrectedException));
                }
                finally
                {
                    //login includes wrong symbols
                    try
                    {
                        var user = new PreRegistrateUser
                            {
                                Login = "******",
                                Password = "******",
                                ConfirmPassword = "******",
                                Email = "*****@*****.**",
                                Info = "dsfsdfsdf"
                            };
                        registration.TryRegistrateUser(user);
                    }

                    catch (Exception ex)
                    {
                        Assert.AreEqual(ex.GetType(), typeof(LoginIncorrectedException));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void TryRegistrateUser(PreRegistrateUser user)
        {
            if (!IsLoginRight(user.Login))
                {
                    return;
                }
                if (!IsPasswordRight(user.Password))
                {
                    return;
                }
                if (!IsConfirmPasswordMatched(user.Password, user.ConfirmPassword))
                {

                    return;
                }
                if (!IsEmailRight(user.Email))
                {

                    return;
                }
                try
                {
                    RegistrateUser(user);
                }
            catch(Exception ex)
            {
                throw new DataBaseBaseException(ex.Message,ex);
            }
        }