Previous Thread
Next Thread
Print Thread
Rate Thread
#104981 01/14/2004 10:18 AM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
I know of the existance of Apache::Htpasswd, which can manage .htpasswd files for Apache servers, but that's not really what I'm looking for.

On a site I'm developing, a user must authenticate him or herself with Apache's basic authentication (.htaccess and .htpasswd). What I'm looking to do is to retrieve the user name the user just logged in with (for use in a personalised greeting). Short of storing a session-long cookie, is there any other way of doing this in Perl?

Sponsored Links
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
Admin Emeritus
Joined: Jan 2000
Posts: 5,073
Damn... when I saw this topic, I was just gonna pop in here and say "use Apache::Htpasswd" and be done with it. tipsy

Do an %ENV dump... I'm pretty sure that the basic auth string will be somewhere in there. Decode the string using MIME::Base64 to get the username and password.


UBB.classic: Love it or hate it, it was mine.
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
Ah, $ENV{REMOTE_USER}. Didn't need to be decrypted either. Great stuff. smile

Thanks again Charles. wink

Joined: Nov 2004
Posts: 2
Junior Member
Junior Member
Offline
Joined: Nov 2004
Posts: 2
Hey, I'm glad I found this topic, probably one of you guys could help me.

I'm loging into a restricted folder using htpasswd/htaccess. Now I access a simple Guestbook, where I want the Username I just use to log in be written in a field (which is part of a cgi-file).

Eventually it would be great to do it like that:
If the htpasswd username is 4 example: "ms2" then it should display in the textfield the Username "Max Smith". Some kina If... then.

Then I could disable the textfield so the user can post only by his real name, according to the htpasswd username he just used.

I'm quite a newbie in that so please explain so that I will understand tipsy


Thanks A LOT!!!
Max

Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
Main question would be where would the real name be stored; the .htaccess file ins't meant to be a database of any kind; the way i'd do it is make it php based, then have a small mysql database containing usernames/passwords/real names (you could do flat file too i guess); then you can have it 'if username = jd then realname = John Doe'


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Sponsored Links
Joined: Mar 2001
Posts: 7,394
LK Offline
Admin / Code Breaker
Admin / Code Breaker
Offline
Joined: Mar 2001
Posts: 7,394
Try:
%names = (
"ms2" => "Max Smith",
"ms1" => "Mark Stone",
"tb" => "Tom Bush",
"etc" => "Whatever",
);

Then
print qq~~;

That's untested but I think it could work.
Note that if it's a type=text, the user can still change the value, but the default one would be from the %names variable.

Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
I'm always a fan of:
Code
<input type="hidden" value="">


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Joined: Mar 2001
Posts: 7,394
LK Offline
Admin / Code Breaker
Admin / Code Breaker
Offline
Joined: Mar 2001
Posts: 7,394
But then they can still modify it by going to the code...
You can give them a 12-char session id, so that they'll have almost no way to change it to another true one. Create a sessions.cgi file in the directory, have a randomly-generated id such as "Fr5g4Dds9aG", in the file have "Fr5g4Dds9aG" => "Max Smith", and then add to the HTML: input type="hidden" name="session" value="Fr5g4Dds9aG".

But that's only if you don't trust them. smile

Joined: Nov 2004
Posts: 2
Junior Member
Junior Member
Offline
Joined: Nov 2004
Posts: 2
Thanks guys, you really helped me a lot!

Your script works fine, LK rockon

I just added a 0nfocus="this.blur()" within the textfield, thats enough for my purposes...
The guestbook is just for about 30 people, no one with a good cgi-knowledge and surely not intending to manipulate those variables... so I don't think I'll have to do further scripting wink

byebye and thanks again,
Max


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Gizmo
Gizmo
Portland, OR, USA
Posts: 5,833
Joined: January 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)