The database is on a remote server. My concern is if I just verify the username and password and then let their program change fields what would stop someone from making their own program that can connect to the database with their username and password and change someone else's fields or access their information.
Solutions to securing a connection to a remote server range from non-existent to very complex.
How complex your solution is depend much on how much time you have to spend on the solution.
Does your B4A application interact with the remote server database using PHP scripts or do you use a .NET technology such as ASP?
I have no experience of .NET but can point you in the right direction if you are using PHP.
First check out the documentation for PHP Sessions:
PHP: Sessions - Manual.
Once your server has successfully authenticated the user - username and password accepted - you'd start a new session.
Each session has a unique id so after starting a new session you need to pass that unique id back to your application.
Now each time your application sends a request to the server it must include that unique session id in the request.
(Depending on how you are connecting to the server that session id may automatically be sent with each request - if you are using a WebView i
think the WebView automatically does this).
The PHP script checks the session id and if it is not the current session id then the script will not process the request.
Look at the example code posted
here:
<?php
// Starting the session
session_start();
if(isset($_SESSION['user']))
{
// Code for Logged members
// Identifying the user
$user = $_SESSION['user'];
// Information for the user.
}
else
{
// Code to show Guests
}
?>
Code for Logging a User:
<?php
//Username Stored for logging
define("USER", "user");
// Password Stored
define("PASS", "123456");
// Normal user section - Not logged ------
if(isset($_REQUEST['username']) && isset($_REQUEST['password']))
{
// Section for logging process -----------
$user = trim($_REQUEST['username']);
$pass = trim($_REQUEST['password']);
if($user == USER && $pass == PASS)
{
// Successful login ------------------
// Setting Session
$_SESSION['user'] = USER;
// Redirecting to the logged page.
header("Location: index.php");
}
else
{
// Wrong username or Password. Show error here.
}
}
?>
You should be able to modifiy that i think.
Sessions automatically timeout after a period, that period depends upon the PHP configuration of your server.
If you have write access to your php.ini file then you can can can change the default timeout period.
I think the default timeout period is 1440 seconds, but it may be that your webhost has changed this default period.
Anyway once your application has finished communicating with the server it is best for the app to send a request to indicate that the app has finished with the current session.
The server can then destroy the current session rather than leaving it to be destroyed after the timeout period set in the php.ini file.
Martin.