Ejemplo n.º 1
0
 /// <summary>
 /// Устанавливает новый пароль пользователю.
 /// </summary>
 /// <param name="password"></param>
 /// <param name="user"></param>
 public static void SetNewPassword(SecureString password, User user)
 {
     if (!PasswordMaker.CheckPassword(password))
     {
         return;
     }
     user.Pass = PasswordMaker.MakeHash(password, user.Salt);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Создаёт пользователя
        /// </summary>
        /// <exception cref="UsernameCollisionException"/>
        /// <exception cref="PasswordStrengthException"/>
        private User CreateUser(string username, SecureString password)
        {
            if (!IsUsernameAvailable(username))
            {
                throw new UsernameCollisionException();
            }

            if (!PasswordMaker.CheckPassword(password))
            {
                throw new PasswordStrengthException();
            }

            var credits = PasswordMaker.MakeSaltedHash(password);

            return(new User()
            {
                Login = username,
                Pass = credits.Item1,
                Salt = credits.Item2
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Пытается авторизовать пользователя по имени и паролю.
        /// </summary>
        /// <exception cref="NoUsernameException" />
        /// <exception cref="FieldConstraintException" />
        public bool TryLogin(string username, SecureString password)
        {
            var user = (from u in DB.Context.Users
                        where u.Login == username
                        select u).SingleOrDefault();

            if (user == null)
            {
                throw new NoUsernameException();
            }

            // сравниваем хеш пароля в базе с вычисленным по паролю
            if (user.Pass == PasswordMaker.MakeHash(password, user.Salt))
            {
                CurrentUser = user;
                return(true);
            }
            else
            {
                throw new FieldConstraintException();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Создает сущность.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public object Create(Entity type)
        {
            var T      = EntityMapper.TypeOf(type);
            var entity = Activator.CreateInstance(T);

            switch (type)
            {
            //case Entity.Settlement:
            //    break;
            case Entity.Street:
                ((Street)entity).Settlement = Current.Settlement ?? null;
                ((Street)entity).StreetType = Current.StreetType ?? null;
                break;

            case Entity.House:
                ((House)entity).Street = Current.Street ?? null;
                break;

            case Entity.Flat:
                ((Flat)entity).House    = Current.House ?? null;
                ((Flat)entity).FlatType = Current.FlatType ?? null;
                break;

            //case Entity.StreetType:
            //    break;
            //case Entity.FlatType:
            //    break;
            case Entity.Meter:
                ((Meter)entity).MeterType    = Current.MeterType ?? null;
                ((Meter)entity).Registration = Current.Registration ?? null;
                break;

            //case Entity.MeterType:
            //    break;
            case Entity.Reading:
                ((Reading)entity).Meter = Current.Meter ?? null;
                ((Reading)entity).Date  = DateTime.Today;
                break;

            case Entity.Payment:
                ((Payment)entity).Registration = Current.Registration ?? null;
                ((Payment)entity).Service      = Current.Service ?? null;
                ((Payment)entity).Date         = DateTime.Today;
                ((Payment)entity).TargetMonth  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                break;

            case Entity.Rate:
                ((Rate)entity).BeginDate = DateTime.Today;
                break;

            //case Entity.Benefit:
            //    break;
            case Entity.Service:
                ((Service)entity).ServiceType = Current.ServiceType ?? null;
                break;

            //case Entity.ServiceType:
            //    break;
            //case Entity.Unit:
            //    break;
            case Entity.Registration:
                ((Registration)entity).PaymentStartDate = DateTime.Today;
                ((Registration)entity).Flat             = Current.Flat ?? null;
                ((Registration)entity).Payer            = Current.Payer ?? null;
                break;

            case Entity.Payer:
                ((Payer)entity).User = Current.User ?? null;
                ((Payer)entity).Sex  = 1;    // male
                if (!uc.IsAdminLoggedIn)
                {
                    ((Payer)entity).User = uc.CurrentUser;
                }
                break;

            case Entity.User:
                ((User)entity).Salt        = PasswordMaker.GenerateSalt();
                ((User)entity).UserGroupID = (byte)uc.GetRegularUserGroup();
                break;
                //case Entity.UserGroup:
                //    break;
            }

            return(entity);
        }