GO 46 !


RD Dreams

MacDizzy

DBS

YADBS

SourceForge

SIX

Rally.co.in

Rossi Files

Open Solaris

Meebo

Crash.net

MotoGP

Beginning of End

Elving's blog

Sandeep's page

Sun Forums

Air Cooled RD

MindStorms

LEGO-Robotics

Track Guide

Track Forum

M's blogs

BikesZone

Kawasaki Triples

PhRack

Metallica

Distance Running

RD Shop

SMX - Solaris Minix

Elephant Story

WD40

Dan's M/C Site

Tunnel Rats

Gatorade

Orkut

Free Science

Spiderman McBride

Racing a Fiat

Forsyth

BSM Archives

Bugatti Veyron

RNR Racing

A simple NSAPI script for Authentication

This is a very simple authentication script using the scripting plugin. The authentication "database" is a simple variable that holds a set of usernames and passwords in the format "username:password".


#
# A simple authentication script using nsapi scripting.
# If an "Authorization header does not exist, send a 401.
# If it exists, get rid of the leading "Basic " part,
# decode the rest, and compare with each entry in our
# authentication "table". if nothing matches, send a
# 401, else let the request proceed.
#

authlist = "honda:CBR600 yamaha:YzfR1 suzuki:giXXXer kawasaki:NinJa"

authfield = $rq.headers.authorization

if $authfield == ""
then
        call unauth
else
        #
        # decode the "Authorization" value and get the user:pass information
        #
        call getuserpass
        #
        # compare the user:pass information with each entry in our authentication list
        #
        call checkuserpass
fi
req aborted

function checkuserpass()
{
        for i in $authlist
        do
                if $i == $authfield
                then
                        #
                        # We have a match. Let the request proceed.
                        #
                        req proceed
                fi
        done
        call unauth
}

function getuserpass()
{
        authfield = substr $authfield 6
        authfield = b64decode $authfield
}

function unauth()
{
        rq.srvhdrs.status = "401 Unauthorized"
        rq.srvhdrs.WWW-authenticate = "basic realm=\"test\""
}

Comments [0]




Trackback URL: http://blogs.sun.com/motor/entry/a_simple_authentication_script
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed