4D v16.3

On 4D Mobile Authentication database method

Home

 
4D v16.3
On 4D Mobile Authentication database method

On 4D Mobile Authentication database method 


 

$1, $2, $3 -> On 4D Mobile Authentication database method -> $0 
Parameter Type   Description
$1  Text in User name
$2  Text in Password
$3  Boolean in True = Digest mode, False = Basic mode
$0  Boolean in True = request accepted, False = request rejected

The On 4D Mobile Authentication database method provides you with a custom way of controlling the opening of 4D Mobile sessions (via REST) on 4D. This database method is mainly intended for filtering connections when setting up a connection between a Wakanda Server and 4D.

When the request to open a 4D Mobile session comes from Wakanda Server by means of the mergeOutsideCatalog() method (general case), the connection identifiers are provided in the header of the request. The On 4D Mobile Authentication database method is called so that you can evaluate these identifiers. You can use the list of users for the 4D database or you can use your own table of identifiers.

Important: When On 4D Mobile Authentication database method is defined (i.e. when it contains code), 4D fully delegates control of 4D Mobile requests to it: any setting made using the "Read/Write" menu on the Web/4D Mobile page of the Database Settings is ignored (see the Design Reference manual).

The database method receives two parameters ($1 and $2) of the Text type and a Boolean ($3), passed by 4D, and returns a Boolean, $0. You must declare these parameters as follows:

  //On 4D Mobile Authentication database method
 C_TEXT($1;$2)
 C_BOOLEAN($0;$3)
 ... // Code for the method

$1 contains the user name and $2 the password used for the connection. 

The password ($2) can be received either in clear or hashed form, depending mode used by the request. This mode is indicated by the $3 parameter to enable you to perform the appropriate processing:

  • If the password is sent in clear (Basic mode), $3 returns False.
  • If it is sent in hashed form (Digest mode), $3 returns True.

When a 4D Mobile connection request comes from Wakanda Server, the password is always sent in hashed form. 

You must check the identifiers of the 4D Mobile connection in the database method. Usually, you check the name and password using a custom user table. If the identifiers are valid, pass True in $0. The request is then accepted; 4D executes it and returns the result in JSON.
Otherwise, pass False in $0; in this case, the connection is rejected and the server returns an authentication error to the sender of the request. 

If the user is referenced in the list of 4D users of the database, you can check the password directly by means of the following statement:

 $0:=Validate password($1;$2;$3)

The Validate password command has been extended to accept a user name as first parameter as well as an optional parameter indicating whether the password is expressed in hashed form.

If you want to use your own list of users external to the 4D database list, you can save their passwords in hashed form using the same algorithm as that used by Wakanda Server when sending the connection request to the On 4D Mobile Authentication database method in $2. To hash a password using this method, you can write:

 $HashedPasswd :=Generate digest($ClearPasswd ;4D digest)

The Generate digest command accepts 4D digest as a hashing algorithm, corresponding to the method used by 4D for its internal management of passwords.

This example only accepts the "admin" user with the password "123" that does not match a 4D user:

  //On 4D Mobile Authentication database method
 C_TEXT($1;$2)
 C_BOOLEAN($0;$3)
  //$1: user
  //$2: password
  //$3: digest mode
 If($1="admin")
    If($3)
       $0:=($2=Generate digest("123";4D digest))
    Else
       $0:=($2="123")
    End if
 Else
    $0:=False
 End if

This example of the On 4D Mobile Authentication database method checks that the connection request comes from one of the two authorized Wakanda servers, saved in the users of the 4D database:

 C_TEXT($1;$2)
 C_BOOLEAN($0)
 ON ERR CALL("4DMOBILE_error")
 If($1="WAK1")|($1="WAK2")
    $0:=Validate password($1;$2;$3)
 Else
    $0:=False
End case

 
PROPERTIES 

Product: 4D
Theme: Database Methods
Number: 3367

 
HISTORY 

Created: 4D v14
Renamed: 4D v14 R3

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)