new-secret.py 616 B

123456789101112131415161718192021222324
  1. import pyotp, pyqrcode, os
  2. # Get some addition data for the QR not used for TOTP
  3. #issuer = input("Issuer: ")
  4. #email = input("E-Mail: ")
  5. issuer = ''
  6. email = ''
  7. # Generate random secret and URL for the QR code
  8. TOTP_SECRET=pyotp.random_base32()
  9. TOTP_URL=pyotp.totp.TOTP(TOTP_SECRET).provisioning_uri(email, issuer_name=issuer)
  10. # Print Secret and QR code
  11. #print(TOTP_SECRET)
  12. #print(pyqrcode.create(TOTP_URL).terminal(quiet_zone=1))
  13. env = open('/mnt/.env', 'w')
  14. env.write("SECRET=" + TOTP_SECRET)
  15. env.close()
  16. qr = open('/mnt/secret.qr', 'w')
  17. qr.write(pyqrcode.create(TOTP_URL).terminal(quiet_zone=1))
  18. qr.close()