ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV Mobile 2025 feature!
This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Mobile specific functions / SMS functions
  • Operating mode
  • Implementing automatic verification by SMS
  • Special cases
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
SMSDetectOneTimeCode (Function)
In french: SMSDétecteCodeUsageUnique
Automatically populates an Edit control with a one-time code received by SMS.
Example
// Listens for the SMS for 5 minutes 
// until an SMS containing the authentication code is received
IF SMSDetectOneTimeCode(OnOneTimeCodeReceived) THEN
	// Displaying a progress bar
	PROGBAR_WAIT_CODE.Visible = True
ELSE
	Error()
END

PROCEDURE OnOneTimeCodeReceived(sCode is string)
// Displays the code
EDT_Code = sCode
// Hides the progress bar
PROGBAR_WAIT_CODE.Visible = False
// Checks the validity of the code
VerifyCode()
Syntax
<Result> = SMSDetectOneTimeCode(<WLanguage procedure>)
<Result>: Boolean
  • if detection has been started,
  • False otherwise.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback") called when the code is received. This procedure has the following format:
PROCEDURE <Procedure name>(<Code received>)
where <Code received> is a string that contains the code received by SMS (or an empty string if an error occurs). If an error occurs, ErrorInfo can be used to retrieve the error message.
Remarks

Operating mode

SMSDetectOneTimeCode starts listening for incoming SMS messages for 5 minutes. If an SMS containing a one-time code is received during this period, the procedure passed to the function is automatically executed using the received code as a parameter, and detection is stopped.
The SMS containing the one-time code must meet the following criteria:
  • it must not exceed 140 bytes.
  • it must contain a one-time code. This code must be a sequence of 4 to 10 digits (at least 6 characters recommended), without separators.
  • it must end with an 11-character string identifying your application.
Example:
Authentication code: 123456
HQ+6aVM7NXq
Note: The string at the end of the SMS is a hash string composed of the following elements:
  • the application package's name.
  • the application's public key certificate.
You can find this string in the Android generation wizard when SMSDetectOneTimeCode is used in the code of the application.

You can also generate this string with the keytool command. For more details, see Keytool command.

Implementing automatic verification by SMS

Implementing automatic SMS verification in a mobile application requires backend processes to verify the user's identity, send the SMS and check the one-time code when it is sent back to the server to perform all the necessary post-verification tasks.
There is no specific way to establish communication between the mobile application and the server.
One possible solution is to expose a REST API with two endpoints:
  • one that receives verification requests with the user details and sends the SMS messages in the expected format
  • one that receives the one-time code received by the application for further processing.
To generate an SMS one-time code, it's recommended to generate a sequence of 6 to 10 random digits, store it in a database table and associate it with a user ID and an expiration date.

Special cases

  • If SMSDetectOneTimeCode is called while detection is already in progress, the call will be ignored and the function will return False.
  • You can get the phone number(s) of the current user with tapiGetNumber.
  • SMSDetectOneTimeCode has no effect in the simulator.
  • SMSDetectOneTimeCode must be called in the main thread, and only when the application is in the foreground.
Business / UI classification: Neutral code
Component: wd300android.aar
Minimum version required
  • Version 2025
Comments
Click [Add] to post a comment

Last update: 09/30/2024

Send a report | Local help