• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript bcryptjs.hash函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中bcryptjs.hash函数的典型用法代码示例。如果您正苦于以下问题:TypeScript hash函数的具体用法?TypeScript hash怎么用?TypeScript hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了hash函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: initTestData

export async function initTestData() {
  if (isProd()) {
    throw new Error("How about you stop calling initTestData in production!")
  }

  await User.insertMany([
    {
      name: "John Smith",
      email: "[email protected]",
      logins: [{
        id: "[email protected]",
        type: "local",
        primary: true,
        password: await bcrypt.hash("johnsmith123", 10),
      }],
    },
    {
      name: "John Doe",
      email: "[email protected]",
      logins: [{
        id: "[email protected]",
        type: "local",
        primary: true,
        password: await bcrypt.hash("johndoe123", 10),
      }],
    },
  ])
}
开发者ID:Majavapaja,项目名称:Mursushakki,代码行数:28,代码来源:mongo.ts


示例2: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'currentPasword' parameter
	const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
	if (currentPasswordErr) return rej('invalid currentPasword param');

	// Get 'newPassword' parameter
	const [newPassword, newPasswordErr] = $.str.get(params.newPassword);
	if (newPasswordErr) return rej('invalid newPassword param');

	// Compare password
	const same = await bcrypt.compare(currentPassword, user.password);

	if (!same) {
		return rej('incorrect password');
	}

	// Generate hash of password
	const salt = await bcrypt.genSalt(8);
	const hash = await bcrypt.hash(newPassword, salt);

	await User.update(user._id, {
		$set: {
			'password': hash
		}
	});

	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:28,代码来源:change_password.ts


示例3: function

 bcrypt.genSalt(10, function(err, salt) {
   if (err) {return next(err); }
   bcrypt.hash(this.password, salt, function(error, hash) {
     if (error) {return next(error); }
     this.password = hash;
     next();
   });
 });
开发者ID:pontsoleil,项目名称:WuWei,代码行数:8,代码来源:user.ts


示例4: async

UserSchema.statics.registerUser = async (user: RegisterRequest): Promise<IUserDocument | undefined> => {
  const doc = new User();
  doc.name = user.name
  doc.email = user.email
  const password = await bcrypt.hash(user.password, PASSWORD_SALT_ROUNDS)
  const newLogin = new LoginId(user.email, LoginType.Local, password)
  doc.logins.push(newLogin);
  return await doc.save();
}
开发者ID:Majavapaja,项目名称:Mursushakki,代码行数:9,代码来源:User.ts


示例5: Promise

 return new Promise((resolve: Function, reject: Function) => {
     bcrypt.hash(password, config.security.bcryptRounds, function(err, passwordHash) {
         if (err) {
             log.error("Failed to generate password hash", JSON.stringify(err, null, '  '));
             reject(new Error(Errors.PASSWORD_ALGORITHM_FAILURE));
             return;
         }
         resolve(encrypt(passwordHash));
     });
 });
开发者ID:PhilipDavis,项目名称:react-redux,代码行数:10,代码来源:password.ts


示例6: next

    bcrypt.genSalt(SALT, (err1, salt) => {
      if (err1) { return next(err1) }

      bcrypt.hash(user.password, salt, (err2, hash) => {
        if (err2) { return next(err2) }

        user.password = hash
        next()
      })
    })
开发者ID:chipp972,项目名称:stock_manager_api,代码行数:10,代码来源:user.ts


示例7: function

const seedInitialData = function(){
    if (!instance['app_user'] || !instance['app_user'].findOneSync({})){
        var defaultUser = new AppUser("[email protected]");
        defaultUser.registrationDate = moment.utc().toISOString();

        bcrypt.hash('password', 10, function(err, hash){
            defaultUser.passwordHash = hash;
            instance.saveDoc('app_user', defaultUser, function(err, res){
                console.log(`User ${res.id} - '${res.email}' is seeded`);
            });
        });
    }
};
开发者ID:dyliew,项目名称:hapi-postgres-typescript-play,代码行数:13,代码来源:index.ts


示例8: next

    bcrypt.genSalt(10, (err, salt) => {
        if (err) {
            return next(err)
        }

        bcrypt.hash(user.password, salt, (err, hash) => {
            if (err) {
                return next(err)
            }

            user.password = hash;
            next();
        })
    });
开发者ID:Antyneskul,项目名称:homeBudgetApi,代码行数:14,代码来源:user.ts


示例9: async

  const signIn = async (input: NexusGenAllTypes['SignInInput']) => {
    const fail = (errors: NexusGenAllTypes['SignInErrors']) => ({
      errors: {
        email: null,
        password: null,
        ...errors,
      },
      token: null,
    });

    const success = (userId: string) => {
      const payload: JsonWebTokenPayload = { userId };
      return {
        errors: null,
        token: jwt.sign(payload, API_SECRET as jwt.Secret),
      };
    };

    const errors = validateSignIn(input);
    if (context.input.hasError(errors)) return fail(errors);

    if (input.createAccount) {
      const exists = await context.prisma.$exists.user({ email: input.email });
      if (exists) return fail({ email: 'ALREADY_EXISTS' });
      const password = await bcrypt.hash(input.password, 10);
      const user = await context.prisma.createUser({
        email: input.email,
        password,
        themeName: '',
      });
      return success(user.id);
    }
    const user = await context.prisma.user({ email: input.email });
    if (!user) return fail({ email: 'NOT_EXISTS' });
    const validPassword = await bcrypt.compare(input.password, user.password);
    if (!validPassword) return fail({ password: 'WRONG_PASSWORD' });
    return success(user.id);
  };
开发者ID:este,项目名称:este,代码行数:38,代码来源:userModel.ts


示例10: async

export default async (event: FunctionEvent<EventData>) => {
  console.log(event);

  try {
    const graphcool = fromEvent(event);
    const api = graphcool.api('simple/v1');

    const { email, password } = event.data;

    if (!validator.isEmail(email)) {
      return { error: 'Not a valid email' };
    }

    // check if user exists already
    const userExists: boolean = await getUser(api, email).then(
      r => r.User !== null,
    );
    if (userExists) {
      return { error: 'Email already in use' };
    }

    // create password hash
    const salt = bcrypt.genSaltSync(SALT_ROUNDS);
    const hash = await bcrypt.hash(password, SALT_ROUNDS);

    // create new user
    const userId = await createGraphcoolUser(api, email, hash);

    // generate node token for new User node
    const token = await graphcool.generateNodeToken(userId, 'User');

    return { data: { id: userId, token } };
  } catch (e) {
    console.log(e);
    return { error: 'An unexpected error occured during signup.' };
  }
};
开发者ID:davidohayon669,项目名称:este,代码行数:37,代码来源:signup.ts



注:本文中的bcryptjs.hash函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript bcryptjs.hashSync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript bcryptjs.genSaltSync函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap