當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript bcryptjs.genSaltSync函數代碼示例

本文整理匯總了TypeScript中bcryptjs.genSaltSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript genSaltSync函數的具體用法?TypeScript genSaltSync怎麽用?TypeScript genSaltSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了genSaltSync函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: hashPassword

function hashPassword(password: string): string {
  if (!password) {
    return null;
  }

  return Bcrypt.hashSync(password, Bcrypt.genSaltSync(8));
}
開發者ID:mlinuxgada,項目名稱:hapi-typescript-example,代碼行數:7,代碼來源:user.ts

示例2: 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

示例3: hashPasswd

export function hashPasswd(password: string): string {
  const salt = bcrypt.genSaltSync(10);
  const hash = bcrypt.hashSync(password, salt);
  return hash;
}
開發者ID:A-Horse,項目名稱:bblist-backend,代碼行數:5,代碼來源:createUser.ts

示例4: generateHash

 generateHash(password) {
   return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
 }
開發者ID:50Hannah000,項目名稱:MDB1,代碼行數:3,代碼來源:authentication.ts

示例5:

const hash_password = ( password ) => {
	let salt = bcrypt.genSaltSync(); // enter number of rounds, default: 10
	let hash = bcrypt.hashSync( password, salt );
	return hash;
};
開發者ID:FazioNico,項目名稱:nodejs-simple-graphql-ts,代碼行數:5,代碼來源:user.models.ts


注:本文中的bcryptjs.genSaltSync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。