[Gambas-user] Request.Header and Base64Decode for a CGI

Toni arosa at ...2015...
Wed Jan 14 22:16:46 CET 2009


Hi,
I'm programming a CGI using Gambas2 and I want to implement "basic http 
authentication" into it, but I have two problems to get it done: I Don't 
know how to get Request HTTP Headers (I couldn't find something like 
"Request.Header[]"). The other problem is that I haven't been able to 
find a decoding Base64 function in Gambas. Is there one?

Here is a sample code of how I wanted to implement it:


PRIVATE SUB Authorize()
  DIM Validated AS Boolean = FALSE
  DIM User AS String = "user"
  DIM SecretPassword AS String = "secret"

  IF Request.Header["Authorization"] <> "" THEN '<----------- 
Request.Header IS AN INVETION
       IF base64_decode(Request.Header["Authorization"]) == (User & "+" 
& SecretPassword) THEN Validated = TRUE '<--------- base64_decode IS AN 
INVETION TOO
  ENDIF
    
  IF (NOT Validated) THEN
    Response.AddHeader("WWW-Authenticate", "Basic realm=\"AgendaXML-WEB\"")
    Response.AddHeader("status", "401 Unauthorized")
    Response.Begin
    Response.End
    QUIT
  END IF
END


Regards,
Toni

PS: I guess I could use the web server authentication mechanisms but I 
just wondered whether I could control it from within my CGI





More information about the User mailing list