Ejemplo n.º 1
0
        public void ChangePassword(string loginName, string oldPassword, string newPassword)
        {
            var spec  = AccountQuery.WithByLoginName(loginName);
            var admin = _account.One(spec);

            if (admin == null)
            {
                throw new Exception(AccountServiceResource.AccountNullException.FormatWith("LoginName", loginName));
            }

            var dbPwdHash = admin.PasswordHash;
            var dbsalt    = admin.PasswordSalt;

            if (dbPwdHash == null || dbsalt == null)
            {
                throw new Exception(AccountServiceResource.PasswordAndSaltNullException);
            }

            var inputPwdHash = EntityUtils.GetInputPasswordHash(oldPassword, dbsalt);

            if (!dbPwdHash.SequenceEqual(inputPwdHash))
            {
                throw new Exception(AccountServiceResource.PasswordInvalidException);
            }

            var salt    = EntityUtils.GenerateRandomBytes(Constants.PasswordSaltLength);
            var pwdHash = EntityUtils.GetInputPasswordHash(newPassword, salt);

            admin.PasswordSalt = salt;
            admin.PasswordHash = pwdHash;

            Context.SaveChanges();
        }
Ejemplo n.º 2
0
        public IEnumerable <Account> GetAllAccount(out int totalRecords,
                                                   int currentPage  = 1,
                                                   int pageSize     = 25,
                                                   string sortBy    = "Id",
                                                   bool descending  = true,
                                                   string loginName = null)
        {
            var spec = AccountQuery.WithAll();

            spec = loginName != null
                    ? spec.And(AccountQuery.WithByLoginName(loginName))
                    : spec;

            totalRecords = _account.Count(spec);
            var sort = Context.Filters.Sort <Account, int>(ti => ti.Id, true);

            switch (sortBy)
            {
            case "Id":
                sort = Context.Filters.Sort <Account, int>(ti => ti.Id, descending);
                break;

            case "Title":
                sort = Context.Filters.Sort <Account, string>(ti => ti.CompanyCode, descending);
                break;

            default:
                break;
            }
            var pager = Context.Filters.Page <Account>(currentPage, pageSize);

            return(_account.Find(spec, sort, pager));
        }
Ejemplo n.º 3
0
 public Account GetByLoginName(string loginName)
 {
     return(_account.One(AccountQuery.WithByLoginName(loginName)));
 }