20260511150000_reset_hardcoded_admin_password.mjs 999 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import bcrypt from 'bcrypt'
  2. import { db } from './lib/mongodb.mjs'
  3. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  4. import { promiseMapWithLimit } from '@overleaf/promise-utils'
  5. const tags = ['server-ce', 'server-pro']
  6. const HARDCODED_PASSWORD = 'password_here'
  7. const CONCURRENCY = parseInt(process.env.CONCURRENCY, 10) || 10
  8. const migrate = async () => {
  9. await batchedUpdate(
  10. db.users,
  11. { hashedPassword: { $type: 'string' } },
  12. async function (batch) {
  13. await promiseMapWithLimit(CONCURRENCY, batch, async user => {
  14. const match = await bcrypt.compare(
  15. HARDCODED_PASSWORD,
  16. user.hashedPassword
  17. )
  18. if (match) {
  19. await db.users.updateOne(
  20. { _id: user._id, hashedPassword: user.hashedPassword },
  21. { $unset: { hashedPassword: 1 } }
  22. )
  23. }
  24. })
  25. },
  26. { hashedPassword: 1 }
  27. )
  28. }
  29. const rollback = async () => {}
  30. export default {
  31. tags,
  32. migrate,
  33. rollback,
  34. }