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


TypeScript bcrypt.genSaltSync函數代碼示例

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


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

示例1: create

	function create(): void {
		const screenName: string = req.body['screen-name'];
		const password: string = req.body['password'];

		if (screenName === undefined || screenName === null || !/^[a-zA-Z0-9\-]{2,15}$/.test(screenName)) {
			res.sendStatus(400);
			return;
		}

		if (password === undefined || password === null || password.length < 8) {
			res.sendStatus(400);
			return;
		}

		// Generate hash of password
		const salt = bcrypt.genSaltSync(14);
		const encryptedPassword = bcrypt.hashSync(password, salt);

		User.create({
			screenName: screenName,
			screenNameLower: screenName.toLowerCase(),
			encryptedPassword: encryptedPassword
		}, (err, user) => {
			if (err !== null) {
				console.error(err);
				res.sendStatus(500);
				return;
			}

			res.sendStatus(200);
		});
	}
開發者ID:syuilo,項目名稱:ssmato.me,代碼行數:32,代碼來源:create.ts

示例2: function

updateRecord = async function(id,data, model){
    let
    user,
    res;

    try {
        user = await model.$findById('id', id, [1]);
    } catch(err) {
        return Promise.reject(err);
    }

    try {
        res  = await bcrypt.compareSync(`|-:${data.oldpwd}:-|`, user.password);

        if(!res)
            return errors.error({
                code  : '104'
            });

        let
        _salt = bcrypt.genSaltSync(12),
        _pwd  = bcrypt.hashSync(`|-:${data.newpwd}:-|`, _salt);

        /** TODO 此處用以下方式更新 password 會提示:
            ValidationError: user validation failed

            user.password = _pwd;
            user = await user.save();
        */

        let
        update = await model.update({
            _id : user._id
        }, {
            $set : {
                password : _pwd
            }
        }).exec();

        return update.ok === 1 ? errors.success(true) : errors.error({
            code : '31'
        });
    } catch(err) {
        return Promise.reject(err);
    }

};
開發者ID:goumang2010,項目名稱:NetTxtNote,代碼行數:47,代碼來源:static.resetPassword.ts

示例3: function

 formatRequestParams = async function (data): Promise<any> {
     data = _trim.statics.$extractParamForInsert.fn(data, inspectSchema);
     //修正phone及email的數據格式
     //const expandarr = ["phone", "email"];
     //expandarr.map(function (name) {
     //    if (data[name]) {
     //        let tmp = data[name];
     //        //將不會改變tmp
     //        data[name] = {
     //            value: tmp,
     //            verified: false
     //        };
     //    }
     //});
     //密碼加鹽
     let
         _salt = bcrypt.genSaltSync(10),
         _pwd = bcrypt.hashSync(`|-:${data.password}:-|`, _salt);
     data['password'] = _pwd;
     return data;
 };
開發者ID:goumang2010,項目名稱:NetTxtNote,代碼行數:21,代碼來源:static.create.ts

示例4: moment

                cursor.next((err, row) => {
                    if (err && err.message.indexOf('No more rows ') > -1) {
                        const salt = bcrypt.genSaltSync(saltRounds);
                        if (!salt) res.status(500).end('User registration failed try again later.');
                        const hash = bcrypt.hashSync(req.body.password, salt);
                        if (!hash) res.status(500).end('User registration failed try again later.');
                        const refresh_token = crypto.randomBytes(20).toString('hex');
                        if (!refresh_token) res.status(500).end('User registration failed try again later.');
                        r.table("users").insert({ isAdmin: false, email: req.body.email, password: hash, refresh_token: refresh_token }).run(req.conn)
                            .then((result) => {
                                const exp = moment().add(3, "months").valueOf();
                                const user = { userId: result.generated_keys[0], email: req.body.email, expires: exp, refresh_token: refresh_token, access_token: jwtoken.sign({ isAdmin: false }, config.SECRET, { issuer: result.generated_keys[0], expiresIn: exp }) };
                                res.set('Content-Type', 'application/json');
                                res.json(user);
                            }, (err) => {
                                console.log(err)
                                res.status(500).end('Internal server error');
                            })
                    } else if (row) {
                        res.end('An account already exists for this email address.');
                    }

                })
開發者ID:triniwiz,項目名稱:mojichat-api,代碼行數:23,代碼來源:users.ts

示例5: function

UserSchema.method("generateHash", function(password: string) {
  return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
});
開發者ID:snyderjk,項目名稱:TheCodeJo,代碼行數:3,代碼來源:user.ts

示例6: encryptPassword

 @BeforeCreate
 static encryptPassword(instance: Account) {
   if (instance.password) instance.password = bcrypt.hashSync(instance.password, bcrypt.genSaltSync(8));
 }
開發者ID:KShewengerz,項目名稱:ngx-express-passport-setup,代碼行數:4,代碼來源:Account.ts

示例7: async

export default async (req: express.Request, res: express.Response) => {
	// Verify recaptcha
	const success = await recaptcha(req.body['g-recaptcha-response']);

	if (!success) {
		res.status(400).send('recaptcha-failed');
		return;
	}

	const username = req.body['username'];
	const password = req.body['password'];
	const name = '名無し';

	// Validate username
	if (!validateUsername(username)) {
		res.sendStatus(400);
		return;
	}

	// Fetch exist user that same username
	const usernameExist = await User
		.count({
			username_lower: username.toLowerCase()
		}, {
			limit: 1
		});

	// Check username already used
	if (usernameExist !== 0) {
		res.sendStatus(400);
		return;
	}

	// Generate hash of password
	const salt = bcrypt.genSaltSync(14);
	const hash = bcrypt.hashSync(password, salt);

	// Generate secret
	const secret = rndstr('a-zA-Z0-9', 32);

	// Create account
	const inserted = await User.insert({
		token: secret,
		avatar_id: null,
		banner_id: null,
		birthday: null,
		created_at: new Date(),
		bio: null,
		email: null,
		followers_count: 0,
		following_count: 0,
		links: null,
		location: null,
		name: name,
		password: hash,
		posts_count: 0,
		likes_count: 0,
		liked_count: 0,
		drive_capacity: 1073741824, // 1GB
		username: username,
		username_lower: username.toLowerCase()
	});

	const account = inserted.ops[0];

	// Response
	res.send(await serialize(account));

	// Create search index
	if (config.elasticsearch.enable) {
		const es = require('../../db/elasticsearch');
		es.index({
			index: 'misskey',
			type: 'user',
			id: account._id.toString(),
			body: {
				username: username
			}
		});
	}
};
開發者ID:syuilo,項目名稱:misskey-core,代碼行數:81,代碼來源:signup.ts

示例8: require

var generatePassword = (password:string) => {
    var bcrypt = require('bcrypt');
    return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
};
開發者ID:locator-kn,項目名稱:ark-database,代碼行數:4,代碼來源:setup.ts

示例9:

import * as bcrypt from 'bcrypt';

const saltRounds = 10;
const myPlaintextPassword = '123123123';
const someOtherPlaintextPassword = 'not_bacon';

const salt = bcrypt.genSaltSync(saltRounds);
const hash = bcrypt.hashSync(myPlaintextPassword, salt);

const v1 = bcrypt.compareSync(myPlaintextPassword, hash);
const v2 = bcrypt.compareSync(someOtherPlaintextPassword, hash);

console.log(salt);
console.log(hash);

console.log(v1);
console.log(v2);
開發者ID:echolaw,項目名稱:work-day,代碼行數:17,代碼來源:testBcrypt.ts

示例10: encryptPassword

export function encryptPassword(password: string): string {
    let salt = bcrypt.genSaltSync(saltRound);
    return bcrypt.hashSync(password, salt);
}
開發者ID:zcg331793187,項目名稱:DownloadYouLike,代碼行數:4,代碼來源:index.ts


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