Sign up and log in with mobile phone verification code

Phone number and SMS verification code login for Discourse.

Version: 1.0.0
Requires Discourse: 3.5.0+
Repository: GitHub - singi2016cn/singi-sms-login: Phone number and SMS verification code login for Discourse · GitHub

This plugin adds a regular authentication provider that lets users register and log in with a phone number and an SMS verification code. It is an optional additional login method and does not replace Discourse’s built-in email/password login.

Features

  • Phone number + SMS code registration and login.
  • Standard provider button, like GitHub or Google.
  • Supports +86, +852, and +853 numbers, with an extensible country registry.
  • Supports Aliyun SMS and Tencent Cloud SMS.
  • Virtual email addresses on the reserved .invalid TLD, so Discourse does not try to deliver mail to them.
  • Users can add and verify a real email address later from their account settings.
  • Existing Discourse gates still apply: invitations, approval, second factor authentication, IP bans, and DiscourseConnect.
  • HMAC-hashed verification codes, single-use consumption, attempt limits, and rate limits.
  • No changes to Discourse core code.

Installation

In a standard Discourse Docker installation:

cd /var/discourse
./launcher enter app
cd plugins
git clone https://github.com/singi2016cn/singi-sms-login.git singi-sms-login
exit
./launcher rebuild app

Then go to Admin → Settings → Login, enable singi_sms_login_enabled, and configure one SMS provider.

How login works

  1. The user clicks the phone login button on the login or signup page.
  2. They enter their phone number and request a code.
  3. They enter the SMS code.
  4. The plugin verifies the code and passes the verified identity to Discourse’s normal OmniAuth callback.
  5. Discourse either logs the user in or takes them through the normal account completion flow.

The login button follows Discourse’s default provider behavior:

  • With local login enabled, the phone button appears alongside the email/password form.
  • With local login disabled, external providers become the main login entry.
  • With local login disabled and only one external provider enabled, Discourse automatically redirects to that provider.

Virtual email addresses

Discourse requires an email address for every user account. This plugin generates one from the normalized phone number:

+8613800138000 -> 8613800138000@sms.invalid
+85291234567   -> 85291234567@sms.invalid
+85366123456   -> 85366123456@sms.invalid

The .invalid TLD is reserved and Discourse does not deliver mail to it. Users can add and verify a real email address later from their account settings.

If your site uses allowed_email_domains, add sms.invalid to the allowlist.

Settings

All settings are under Admin → Settings → Login → Phone Login.

Setting Description
singi_sms_login_enabled Enable the provider and login button.
singi_sms_login_button_title Label shown on the login button.
singi_sms_login_provider SMS provider: aliyun or tencent.
singi_sms_login_aliyun_access_key Aliyun AccessKey ID.
singi_sms_login_aliyun_access_secret Aliyun AccessKey secret.
singi_sms_login_aliyun_sign_name Aliyun SMS signature.
singi_sms_login_aliyun_template_code Aliyun SMS template code.
singi_sms_login_tencent_sdk_app_id Tencent Cloud SMS SDK AppId.
singi_sms_login_tencent_secret_id Tencent Cloud SecretId.
singi_sms_login_tencent_secret_key Tencent Cloud SecretKey.
singi_sms_login_tencent_sign_name Tencent Cloud SMS signature.
singi_sms_login_tencent_template_id Tencent Cloud SMS template ID.
singi_sms_login_code_ttl_minutes Code lifetime in minutes. Default: 5.
singi_sms_login_resend_seconds Resend cooldown in seconds. Default: 60.
singi_sms_login_max_attempts Failed attempts before a code is discarded. Default: 5.
singi_sms_login_allow_connect_existing_user Allow logged-in users to connect a phone number to an existing account. Keep disabled to prevent account takeover.

API credentials are marked as secrets and are not sent to the browser.

Usage notes

  • Use a real SMS signature and template approved by your SMS provider.
  • Codes are stored as HMAC hashes, never as plaintext.
  • Codes expire after singi_sms_login_code_ttl_minutes.
  • Codes are consumed once after a successful verification.
  • Rate limits apply per phone number, per IP, and globally to prevent abuse and unexpected SMS costs.
  • By default, users cannot take over an existing account just by entering its phone number.
  • If your site uses allowed_email_domains, add sms.invalid to the allowlist.
  • Disabling the plugin removes the login button and plugin routes. Existing associated accounts are preserved.

Limitations

  • A virtual .invalid email address cannot receive email. Email-based password recovery will not work until the user adds a real email address.
  • Phone numbers can be recycled by carriers. If account takeover is a concern, require users to add a real email address or keep another login method enabled.
  • This plugin does not perform legal identity verification. Local regulations may require additional checks.
  • Only Aliyun and Tencent Cloud are supported in this version. The provider layer is abstracted so more providers can be added later.
1 Like