Mensa India Database Database
Home
Services
Auth Service
Naming Service
Reminder Service

Keys

Authentication Service


Remote User Authentication

The Remote User Authentication service allows for mensa websites to authentication mensa members.
The Mensa database provides all members with a username and password, this username and password pair can be used to authenticate users on any remote site. The advantages are that mensa members need only remember one password for all mensa activities. Also this system does not allow expired members to access member content.

Authentication is done by calling one of the authentication files : http://indianmensa.org/db/services/auth/auth.php or http://indianmensa.org/db/services/auth/authXML.php.
The username and password are passed as GET parameters. To specify the username use the "user" parameter and for password use the "pass" parameter.

Example

To authenticate a user with the Membership No (The Membership No acts as the username, uniquely identifying each user) 11000012 and password testpass, you will make a call as follows :
http://indianmensa.org/db/services/auth/auth.php?user=11000012&pass=testpass

If your website is chapter specific where you want to limit your users to a certain chapter you may use the City parameter. Each chapter is assigned a 2 character code as shown in the table below :

CodeCity
Mumumbai
Kokolkata
Chchennai
Dedelhi
Pupune
Babangalore
Hyhyderabad

Example

To authenticate a user with the Membership No 11000012, password testpass and from the Mumbai chapter, you will make a call as follows :
http://indianmensa.org/db/services/auth/auth.php?user=11000012&pass=testpass&City=Mu

The resulting page is a plain text file with 2 lines. The first line gives the result code and the second line gives a description. Below is a list of the codes and their descriptions

CodeDescriptionExplanation
1Valid UserThe username and password are valid and the member has paid his dues.
0Invalid UserThe username and password (and if used the City parameter) did not yield a match. User cannot be authenticated.
-1Membership ExpiredThe user exists but his membership has expired.
-2Username or Password not provided.Error produced when username or password are not provided to the script.

The file http://indianmensa.org/db/services/auth/authXML.php returns the same output but parses it as XML.



How to use these files for authentication.

Performing authentication with the help of these files is simple. You can write a function that calls this page and read its output.

Code Example

Say you are using PHP, your function would be as follows.

<?php
function authUser($username,$pass,&$message)
{
//Note the inclusion of City=Mu. This would mean access is restricted only to mumbai members.
$loc="http://indianmensa.org/db/services/auth/auth.php?user=$username&pass=$pass&City=Mu";
$fp=fopen($loc,"r");
$ret = fgets($fp,10);
$message = fgets($fp,100);
return $ret;
}
?>

Now you can call this function to authenticate users.

<php
$msg="";
if (authUser($_POST['login'],$_POST['pass'],$msg)==1){/*User valid,perform login functions.*/}
else {print ($msg);}
?>

This was merely an example using the plain text file. If you wish to you can use the XML file authXML.php. The GET parameters remain the same only the output format differs. The XML file can be used with PHP's XML functions or for that matter with any other language that supports reading XML. The main reason for including the XML file was to support future projects that may incorporate AJAX.


Example AJAX Implementation (using authXML.php)
Username : Password :


Valid XHTML Valid CSS PHP
Copyright (c) 2008 Indian Mensa
The Mensa logo is a registered trademark of Mensa International Limited, all rights reserved.
Mensa does not hold any opinion, or have or express any political or religious views.