code,shows,your,visitors,Basic,Authentication
Quick Search for:  in language:    
code,shows,your,visitors,Basic,Authentication
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 118,709 lines
 Jobs: 148 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Getting a random record from a table
By Serkan YOGURAN on 6/11


cool circle and line drawer
By john sheridan on 6/10


Click here to see a screenshot of this code!A Site Manager with Free Upload Functions (without payable components)
By Francisco J Riquelme on 6/10

(Screen Shot)

Simple Calculator
By Alistair Rodrigues on 6/9


Nutty Password
By jason mulryan on 6/9


Enviar email HTML ( send an email html )
By Javi P. D. on 6/9


Banner (rotacion de banners)
By Javi P. D. on 6/9


Paginar ( Paging )
By Javi P. D. on 6/9


Click here to see a screenshot of this code!Online photo catalogue VBScript
By Ivan Loire on 6/8

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Complete working Basic Authentication

Print
Email
 
VB icon
Submitted on: 8/5/2000 8:22:48 AM
By: Almar Joling  
Level: Beginner
User Rating: By 21 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 23928 times.
 

(About the author)
 
     This code shows your visitors the Basic Authentication dialog (or NT Login Dialog) It also returns the password and the username If you like it, please vote for this 16 year old programmer :o)

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    '**************************************
    ' for :Complete working Basic Authentica
    '     tion
    '**************************************
    The Base64 decryption algorithm I used came from http://www.aspcode.net. Showing the dialog is completely by me
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Complete working Basic Authentic
    '     ation
    ' Description:This code shows your visit
    '     ors the Basic Authentication dialog (or 
    '     NT Login Dialog)
    It also returns the password and the username
    if you like it, please vote For this 16 year old programmer :o)
    ' By: Almar Joling
    '
    ' Inputs:In the dialog the username and 
    '     password (/and domain)
    '
    ' Returns:The password and username give
    '     n by the visitors of your site
    '
    ' Assumes:Paste it and run it. It does n
    '     ot verify any usernames or so.
    '
    ' Side Effects:Protects your site :o))
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.6300/lngWId.4/qx/vb/scripts/ShowCode.
    '     htm    'for details.    '**************************************
    
    <%
    Response.Buffer = True
    Response.Clear
    Dim Myname, MyPass
    GetUser Myname, MyPass
    Response.Write MyName & "->" & MyPass
    if len(Myname) = 0 Then
    Response.Status = "401 Unauthorized"
    Response.AddHeader "WWW-Authenticate","BASIC Realm=enter your realm here"
    Response.End
    End if
    Sub GetUser(LOGON_USER, LOGON_PASSWORD)
    Dim UP, Pos, Auth
    Auth = Request.ServerVariables("HTTP_AUTHORIZATION")
    LOGON_USER = ""
    LOGON_PASSWORD = ""
    if LCase(Left(Auth, 5)) = "basic" Then
    UP = Base64Decode(Mid(Auth, 7))
    Pos = InStr(UP, ":")
    if Pos > 1 Then
    LOGON_USER = Left(UP, Pos - 1)
    LOGON_PASSWORD = Mid(UP, Pos + 1)
    End if
    End if
    End Sub
    ' Decodes a base-64 encoded string.
    function Base64Decode(base64String)
    Const Base64CodeBase = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    Dim dataLength, Out, groupBegin
    dataLength = Len(base64String)
    Out = ""
    if dataLength Mod 4 <> 0 Then
    Err.Raise 1, "Base64Decode", "Bad Base64 string."
    Exit function
    End if
    ' Now decode each group:
    For groupBegin = 1 To dataLength Step 4
    Dim numDataBytes, CharCounter, thisChar, thisData, groupData
    ' Each data group encodes up To 3 actual
    '     bytes.
    numDataBytes = 3
    groupData = 0
    For CharCounter = 0 To 3
    ' <B>Convert</B> each charac
    '     ter into 6 bits of data, And add it To
    ' an integer For temporary storage. If a
    '     character is a '=', there
    ' is one fewer data byte. (There can onl
    '     y be a maximum of 2 '=' In
    ' the whole string.)
    thisChar = Mid(base64String, groupBegin + CharCounter, 1)
    if thisChar = "=" Then
    numDataBytes = numDataBytes - 1
    thisData = 0
    Else
    thisData = InStr(Base64CodeBase, thisChar) - 1
    End if
    if thisData=-1 Then
    Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
    Exit function
    End if
    groupData = 64 * groupData + thisData
    Next
    ' Convert 3-byte integer into up To 3 ch
    '     aracters
    Dim OneChar
    For CharCounter = 1 To numDataBytes
    Select Case CharCounter
    Case 1: OneChar = groupData \ 65536
    Case 2: OneChar = (groupData And 65535) \ 256
    Case 3: OneChar = (groupData And 255)
    End Select
    Out = Out & Chr(OneChar)
    Next
    Next
    Base64Decode = Out
    End function
    %>


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/5/2000 11:10:41 AM:Lewis Moten
Have you found a way to create a 
username and password list for basic 
authentication rather then working with 
a predefined realm?  I work with a 
shared server and I can not add users 
to the realm.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/6/2000 4:43:07 AM:Almar Joling
I don't exactly know what you mean, but 
I think this is right: 
Hmm, the realm 
is so far I know not completely 
neccassary.
This code gives you the 
username and the password. If you 
verify this with a userlist containing 
password and username everything should 
be ok.
If you want to change the 
realm you can simply but an other 
string (for example from a database) 
after the "Realm"
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2000 10:05:58 AM:KayHan
this code is not that bad but you can 
get through it without entering the 
password...Do check the code again.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/12/2000 9:34:12 AM:Lewis Moten
Something must be wrong.  It keeps 
asking me for a username and password 
unless I hit cancel.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/13/2000 6:55:03 AM:Almar Joling
KayHan: It does not verify any password 
or usernames. When someone enters a 
username and password you must verify 
it before anything is returned. If the 
password/username is not correct it 
just should return "Access 
Unauthorised" by sending the status 
"401".
I'll have another check on the 
code, and add a database system behind 
it ;o)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/22/2000 4:23:06 PM:TallyOh
In response to your question about the 
basic authentication script for ASP 
always prompting for your name/password 
until you hit cancel.....
In order 
for this to work, you have to turn 
Basic authentication OFF on your IIS 
Webserver.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/30/2000 9:30:28 PM:Optimus Primal
Well done Almar. I've been looking for 
a script that would display the 
browser's authentication dialog... and 
this one works great. Now all I have to 
do is verify against a database of 
users and everythign will be sweet. 
Thanks heaps - you got my vote for sure!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/3/2000 9:10:45 PM:mango
I just wrote a comment on your other 
articles site saying that I think this 
is not only wonderfully useful code, 
but its simple, there are some 
milestones you have to get around (eg. 
no server side includes before adding 
to the header, and make sure basic and 
ntlm is turned off. Thanks a bundle 
Almar, this code is now being used on 
our companys private access area
Cheers
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/26/2001 3:45:12 AM:Beginner
I m a beginner. Although u have 
provided the code , but i still dunno 
what to do with the code. Paste it?In 
where?Or use it to create a new .asp?I 
would like secured my page from 
exposing to others n the password is 
default but users name aren't.Would 
this code help me?Thanks for reply.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/13/2001 9:10:06 PM:Chris Chenoweth
This is excellent code for an ASP 
developer.  Thanks!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/30/2001 11:34:26 AM:andy
hi i dont really know what to do with 
the code, I have only just started 
using ASP. I can get the login screen 
to come up but can someone please help 
me on what to do next to get it to work 
?? Thank you
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/11/2001 9:56:39 PM:Preben Nyloekken
Wounder full, just wounderfull, I've 
been looking for a script like this. 
But I wanted to use this with a 
database, but can't make that work. 
Could you please submit a new version 
of your absolute WOUNDERFULL code!? If 
needed this Sooooo long, and I'm nearly 
there. I have over 1000 visitors daily 
on my website, I'll give you huge 
credit there if you can help me??PLEASE 
PLEASE PLEASE help me.....and again 
wounderful script...Keep it ut 
man!
Please reply on my 
post.
Yours sincerely
Preben 
Nyloekken
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/12/2001 2:14:16 AM:Almar Joling
It's time I made a small "faq" for 
this... I recently discovered *very* 
much replies on this code, and my other 
ASP code, but I never checked that 
email account anymore. I'm grateful 
sorry that I never replied to any of 
your messages.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/5/2001 11:05:26 AM:Gary
Anyway to make windows not want to 
remember the password?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/8/2001 5:09:45 AM:John
Hi,
  Can you tell me the way to 
reauthenticate(by prompting the CR 
window again) the user after he signs 
out of the site and choses to login 
again. 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/23/2002 3:08:35 PM:Farooq
Dam cool
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/25/2002 3:57:40 PM:Raghu
It's pretty good that this tool is 
developed. It'll be useful for most of 
the application..thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.