Authenticating users

UltraLite databases are created with a default user ID of DBA and default password of sql; you must first connect as this initial user. New users must be added from an existing connection.

A user ID cannot be changed; instead, you add the new user ID and then delete the existing user ID. A maximum of four user IDs are permitted for each UltraLite database.

On Palm OS, if you want to authenticate users whenever they return to an application from some other application, you must include the prompt for user and password information in your PilotMain routine.

User authentication example

A complete sample can be found in the samples-dir\UltraLite\esqlauth directory. The code below is taken from samples-dir\UltraLite\esqlauth\sample.sqc.

//embedded SQL
app() {
   ...
/* Declare fields */
   EXEC SQL BEGIN DECLARE SECTION;
      char uid[31];
      char pwd[31];
   EXEC SQL END DECLARE SECTION;
   db_init( &sqlca );
   ...
   EXEC SQL CONNECT "DBA" IDENTIFIED BY "sql";
   if( SQLCODE == SQLE_NOERROR ) {
      printf("Enter new user ID and password\n" );
      scanf( "%s %s", uid, pwd );
      ULGrantConnectTo( &sqlca,
         UL_TEXT( uid ), UL_TEXT( pwd ) );
      if( SQLCODE == SQLE_NOERROR ) {
         // new user added: remove DBA
         ULRevokeConnectFrom( &sqlca, UL_TEXT("DBA") );
      }
      EXEC SQL DISCONNECT;
   }
   // Prompt for password
    printf("Enter user ID and password\n" );
    scanf( "%s %s", uid, pwd );
    EXEC SQL CONNECT :uid IDENTIFIED BY :pwd;

The code carries out the following tasks:

  1. Initiate database functionality by calling db_init.

  2. Attempt to connect using the default user ID and password.

  3. If the connection attempt is successful, add a new user.

  4. If the new user is successfully added, delete the DBA user from the UltraLite database.

  5. Disconnect. An updated user ID and password is now added to the database.

  6. Connect using the updated user ID and password.

See: