当前位置: 首页>>代码示例>>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;未经允许,请勿转载。