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

TypeScript bcryptjs.hashSync函数代码示例

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

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



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

示例1: function

        handler: async function (req, res, next) {
            const payload: Requests.UpdatePassword = req.validatedBody;
            let user = await UserDb.get(req.user._id);

            // Ensure the user's current password is correct
            if (!compareSync(payload.old_password, user.hashed_password)) {
                return next(boom.forbidden(`Your current password is incorrect.`));
            }

            // Change the user's password
            user.hashed_password = hashSync(payload.new_password);

            try {
                const updateResult = await UserDb.put(user._id, user, user._rev);
                user._rev = updateResult.rev
            } catch (e) {
                inspect("Failed to update user's password.", e);

                return next(e);
            }

            await res.withSessionToken(user);

            return next();
        }
开发者ID:nozzlegear,项目名称:Gearworks,代码行数:25,代码来源:users.ts


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


示例3: initialize

    /**
	 * Initializes the comms controller
	 */
    async initialize( db: mongodb.Db ): Promise<void> {
        let cfg = this._cfg;

        // Throw error if no socket api key
        if ( !cfg.websocket.socketApiKey )
            throw new Error( 'The socketApiKey was not set in the config file. Make sure it exists (Check the example-config.json) ' );

        this._hashedApiKey = bcrypt.hashSync( cfg.websocket.socketApiKey );

        // dummy request processing - this is not actually called as its handed off to the socket api
        const processRequest = function( req, res ) {
            req; // Suppress compiler warning
            res.writeHead( 200 );
            res.end( 'All glory to WebSockets!\n' );
        };

        // Create the web socket server
        if ( cfg.ssl ) {
            winston.info( 'Creating secure socket connection', { process: process.pid } );
            let httpsServer: https.Server;
            const caChain = [ fs.readFileSync( cfg.sslIntermediate ), fs.readFileSync( cfg.sslRoot ) ];
            const privkey = cfg.sslKey ? fs.readFileSync( cfg.sslKey ) : null;
            const theCert = cfg.sslCert ? fs.readFileSync( cfg.sslCert ) : null;

            winston.info( `Attempting to start Websocket server with SSL...`, { process: process.pid } );
            httpsServer = https.createServer( { key: privkey, cert: theCert, passphrase: cfg.sslPassPhrase, ca: caChain }, processRequest );
            httpsServer.listen( cfg.websocket.port );
            this._server = new ws.Server( { server: httpsServer } );
        }
        else {
            winston.info( 'Creating regular socket connection', { process: process.pid } );
            this._server = new ws.Server( { port: cfg.websocket.port } );
        }

        winston.info( 'Websockets attempting to listen on HTTP port ' + this._cfg.websocket.port, { process: process.pid } );

        // Handle errors
        this._server.on( 'error', ( err ) => {
            winston.error( 'Websocket error: ' + err.toString() );
            this._server.close();
        } );

        // A client has connected to the server
        this._server.on( 'connection', ( ws: ws ) => {
            this.onWsConnection( ws );
        } );

        // Setup the socket API
        new SocketAPI( this );
    }
开发者ID:Webinate,项目名称:users,代码行数:53,代码来源:comms-controller.ts


示例4: postSettings

export async function postSettings(server: Server, request: Request, reply: IReply)
{
    function view(error: string, success?: boolean)
    {
        const props: SettingsProps = {
            title: "Account Settings.",
            success: !!success,
        }

        return reply.view("account/settings.js", props);
    }

    const validation = joi.validate<{newPassword: string, oldPassword: string, confirmPassword: string}>(request.payload, JoiValidation.postSettings);

    if (validation.error)
    {
        return view(humanizeError(validation.error));
    }

    const payload = validation.value;

    if (payload.confirmPassword !== payload.newPassword)
    {
        return view("New Password does not match the confirmation.");
    }

    const user = await Users.get<User>(request.auth.credentials.userId);

    // Ensure the user's current password is correct
    if(! compareSync(payload.oldPassword, user.hashedPassword))
    {
        return view("Old Password does not match.");
    }
    
    // Change the user's password
    user.hashedPassword = hashSync(payload.newPassword, 10);

    const update = await Users.put(user);

    if (!update.ok)
    {
        console.error("Failed to update user's password.", update);

        return reply(boom.expectationFailed("Failed to update user's password.", update));
    }

    await setUserAuth(request, user);

    return view(undefined, true);
}
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:50,代码来源:account-routes.ts


示例5: postResetPassword

export async function postResetPassword(server: Server, request: Request, reply: IReply): Promise<IBoom | Response>
{
    const payload: {password: string, token: string, confirmPassword: string} = request.payload;
    const validation = joi.validate(payload, JoiValidation.resetPassword);
    const props: ResetPasswordProps = {
        title: "Reset your password.",
        token: payload.token,
    }

    if (validation.error)
    {
        props.error = humanizeError(validation.error);

        return reply.view("auth/reset_password.js", props);
    }

    if (payload.confirmPassword !== payload.password)
    {
        props.error = "Passwords do not match.";

        return reply.view("auth/reset_password.js", props);
    }

    // Ensure the user's password token is still valid
    const user = await findUserByPasswordResetToken(payload.token);

    if (!user || user.passwordResetToken !== payload.token || new Date(user.passwordResetRequestedAt as string) < new Date(new Date().getTime() - (30 * 60 * 1000) /* 30 minutes */))
    {
        props.error = "Your password reset request has expired.";

        return reply.view("auth/reset_password.js", props);
    }

    // Reset user's password
    user.passwordResetToken = undefined;
    user.passwordResetRequestedAt = undefined;
    user.hashedPassword = hashSync(payload.password, 10);

    const update = await Users.put(user);

    if (!update.ok)
    {
        console.error("Failed to save user's new password during password reset request.", update);

        return reply(boom.expectationFailed("Failed to save user's new password during password reset request.")); 
    }

    return reply.redirect(Routes.GetLogin);
}
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:49,代码来源:auth-routes.ts


示例6: fromJSON

	fromJSON(o: any): void
		{
			this.ns = o.ns;
			this.id = o.id;
			this.token = o.token;
			this.name = o.name;
			this.email = o.email;
			if (o.hash)
				this.hash = o.hash;
			if (o.password)
				this.hash = bcrypt.hashSync(o.password, 8);
			this.sessions = o.sessions;
			if (this.sessions == null)
				this.sessions = {};
		}
开发者ID:terrencecrowley,项目名称:ot-server,代码行数:15,代码来源:users.ts


示例7: setUserAuth

export async function setUserAuth(request: Request, user: User)
{
    const hash = bcrypt.hashSync(EncryptionSignature, 10);
    const cookie: AuthCookie = {
        encryptionSignature: hash,
        userId: user._id.toLowerCase(),
        username: user.username,
    }

    try
    {
        await setUserCache(user);
    }
    catch (e)
    {
        console.error("Error setting user cache data.");

        throw e;
    }
    
    return request.yar.set(cookieName, cookie);
}
开发者ID:yashodhank,项目名称:deliver-on,代码行数:22,代码来源:auth.ts


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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript bcrypto.secp256k1类代码示例发布时间:2022-05-25
下一篇:
TypeScript bcryptjs.hash函数代码示例发布时间: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