簡體   English   中英

我們如何構建一個節點 api 它將向用戶發送郵件並生成 otp 以訪問我的 python 微服務

[英]How can we build a node api which will send mail to users and will also generate otp for accessing my python microservices

Is there a way to write an email API on nodejs so that an email containing unique auto-generated OTP will be sent to the user in order to access my python micro-services?

Nodemailer是一個流行的模塊,用於在 nodejs 中發送 email。 您可以在網站上找到所有詳細信息。

或者,您可以使用第 3 方 API 來處理交易電子郵件。 以我的經驗, SendGrid完成了這項工作,並且有一個易於實現的簡潔 API。

就 OTP 而言,您可以使用任何您喜歡的方式來生成密碼,只是永遠不要使用Math.random ,因為它不安全。 一般來說,這就是我構建我的應用程序的方式:

  1. 使用generate-password或您認為合適的方式生成 OTP
  2. 將 OTP hash 保存到數據庫中(您不應將實際密碼存儲到數據庫中)
  3. 使用 Nodemailer 或第 3 方交易 email 提供程序發送 email 與您的鏈接
  4. 一旦用戶按照指示執行操作,您將 OTP hash 與您保存在數據庫中的 hash 進行比較,並做出相應的反應

如果您需要任何代碼示例或其他任何內容,請告訴我,我將編輯我的答案。 希望這可以幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM