Docker本地部署overleaf后,挖掘用户加密逻辑

overleaf的用户信息,保存在mongo数据库的users集合中。

用户密码则存在hashedPassword字段中

 从开源的代码services\web\app\src\Features\Authentication\AuthenticationManager.js第303行可以找到密码加密逻辑。

本地可以通过下面的代码生成overleaf用户密码信息。

npm install bcryptjs
const bcrypt = require('bcryptjs'); // 使用 bcryptjs 模块
const BCRYPT_ROUNDS = 12; // 定义哈希轮数

async function hashPassword(password) {
    try {
        // 生成盐
        const salt = await bcrypt.genSalt(BCRYPT_ROUNDS,'a');
        // 使用盐对密码进行哈希
        const hashedPassword = await bcrypt.hash(password, salt);
        return hashedPassword;
    } catch (error) {
        console.error('Error hashing password:', error);
        throw error;
    }
}

async function exampleUsage() {
	// 定义明文密码
    const plainPassword = '111111';
    console.log('明文密码:', plainPassword);
    // 哈希密码
    const hashedPassword = await hashPassword(plainPassword);
    console.log('Hashed密码:', hashedPassword);
}

// 运行示例
exampleUsage();

通过该功能可实现其它系统与overleaf系统用户信息同步。

只需将用户信息写入mongo的users集合中即可。

补充,还有生成referal_id和_id的代码:

/*生成referal_id*/
const crypto = require('crypto')
function _randomString(length, alphabet) {
		const result = crypto
			.randomBytes(length)
			.toJSON()
			.data.map(b => alphabet[b % alphabet.length])
			.join('')
		return result
}
function generateReferralId() {
	return _randomString(16, TOKEN_ALPHANUMERICS)
}
const TOKEN_LOWERCASE_ALPHA = 'bcdfghjkmnpqrstvwxyz'
const TOKEN_NUMERICS = '123456789'
const TOKEN_ALPHANUMERICS = TOKEN_LOWERCASE_ALPHA + TOKEN_LOWERCASE_ALPHA.toUpperCase() + TOKEN_NUMERICS
const newReferralId = generateReferralId()
console.log(newReferralId)
/*生成_id*/
const { ObjectId } = require('mongodb')
user_id = new ObjectId().toString()
console.log(user_id)

相关推荐

  1. Docker本地化部署加速软件开发周期的利器

    2024-04-29 21:18:04       66 阅读
  2. 使用docker搭建overleaf环境

    2024-04-29 21:18:04       39 阅读
  3. 前端部署提示用户刷新页面

    2024-04-29 21:18:04       25 阅读
  4. 如何部署本地dockers镜像源

    2024-04-29 21:18:04       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-29 21:18:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-29 21:18:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-29 21:18:04       87 阅读
  4. Python语言-面向对象

    2024-04-29 21:18:04       96 阅读

热门阅读

  1. 【python类】为什么需要__init__,为什么需要self

    2024-04-29 21:18:04       33 阅读
  2. 经典排序算法总结

    2024-04-29 21:18:04       37 阅读
  3. 【android 问题 之--自问自答】

    2024-04-29 21:18:04       31 阅读
  4. 【RabbitMQ 一】RabbitMQ简介、消息中间件、MQ的作用

    2024-04-29 21:18:04       35 阅读
  5. [C++] 小游戏 斗破苍穹2.11.1 版本 zty出品

    2024-04-29 21:18:04       31 阅读
  6. 【抽代复习笔记】15-群(九):凯莱定理

    2024-04-29 21:18:04       29 阅读
  7. CSS--选择器

    2024-04-29 21:18:04       29 阅读
  8. C++基础经典算法题(必刷)

    2024-04-29 21:18:04       32 阅读
  9. C# 获取一个字符串中数字部分?

    2024-04-29 21:18:04       30 阅读
  10. python中json.dumps将中文变成unicode字符的解决办法

    2024-04-29 21:18:04       30 阅读
  11. Spring Boot应用部署 - War包部署

    2024-04-29 21:18:04       36 阅读