Beispiel #1
0
 public void Setup()
 {
     _passwords = new PasswordDictionary();
     _store     = A.Fake <IPasswordStore>();
     A.CallTo(() => _store.Load()).Returns(_passwords);
     _manager = new PasswordManager(_store);
 }
Beispiel #2
0
        //----------------------
        // 已经登录了的用户修改密码
        public async Task <bool> UpdatePwd(long?userId, string oldPwd, string pwd)
        {
            var user = dataContext.User.Where(b => b.UserId == userId).First();

            IPasswordStore passwordStore = passwordStoreFactory.Instance(user);
            //验证旧密码
            var vd = passwordStore.VerifyPassword(user.Pwd.Base64ToByteArray(), oldPwd.Base64ToByteArray(), user.Salt.Base64ToByteArray(), user.PasswordHashIterations);

            if (!vd)
            {
                return(vd);
            }
            //产生新的盐
            var salt = RandomTool.CreatSafeSaltByteArray(16);

            passwordStore = passwordStoreFactory.Instance(Config.SecurityConfig);
            //更新用户生成密码哈希的安全策略
            user.PasswordDegreeOfParallelism = Config.SecurityConfig.PasswordStoreDegreeOfParallelism;
            user.PasswordHashAlgorithm       = Config.SecurityConfig.PasswordHashAlgorithm;
            user.PasswordHashIterations      = Config.SecurityConfig.PasswordHashIterations;
            user.PasswordMemorySize          = Config.SecurityConfig.PasswordStoreMemorySize;
            //更新盐
            user.Salt = salt.ByteArrayToBase64();
            //生成新的密码哈希
            user.Pwd = (passwordStore.Encryption(pwd.Base64ToByteArray(), salt, user.PasswordHashIterations)).ByteArrayToBase64();
            if (this.Config.SecurityConfig.LogNeedHmac)
            {
                //计算hmac
                user.AddMac(this.cryptographyProvider);
            }
            return(dataContext.SaveChanges() > 0);
        }
Beispiel #3
0
 public AuthService(DataContext dataContext, IPasswordStore passwordStore, NotebookService notebookService, ConfigFileService configFileService, IDistributedIdGenerator idGenerator, PasswordStoreFactory passwordStoreFactory)
 {
     this.idGenerator          = idGenerator;
     this.dataContext          = dataContext;
     this.passwordStore        = passwordStore;
     this.NotebookService      = notebookService;
     this.config               = configFileService.WebConfig;
     this.passwordStoreFactory = passwordStoreFactory;
 }
 /****************************************************************************/
 public PasswordManager(IPasswordHasher passwordHasher,
                        IPasswordStore passwordStore,
                        IEncryptor saltEncryptor,
                        int saltLength = 32)
 {
     _passwordHasher = passwordHasher;
     _passwordStore  = passwordStore;
     _encryptor      = saltEncryptor;
     _saltLength     = saltLength;
 }
 public UserController(IPasswordStore passwordStore)
 {
     _passwordStore = passwordStore;
 }
Beispiel #6
0
 public PasswordManager(IPasswordStore passwordStore)
 {
     _passwordStore = passwordStore;
     _passwords     = _passwordStore.Load();
 }
 public OneTimePasswordService(IPasswordStore passwordStore, IConfiguration configuration)
 {
     this.passwordStore = passwordStore;
     this.configuration = configuration;
 }
        internal async Task UpdatePassword(IPasswordStore <TUser> passwordStore, TUser user, string newPassword)
        {
            await passwordStore.SetPasswordAsync(user, newPassword);

            return;
        }
 public PasswordGenerator(IPasswordStore passwordStore)
 {
     _passwordStore = passwordStore;
 }