Forum Moderators: open

Message Too Old, No Replies

Creating an .htpasswd file from mysql entries

         

Seamless

11:03 am on Dec 2, 2005 (gmt 0)

10+ Year Member



Hi there,

I was wondering if there was a way to create an .htpasswd file from entries in a mysql databaes.

I have all my users stored in my database and want the to have access to a certain part of my site. Is there any way of linking the 2?

Thanks in advance

Seamless

physics

4:22 pm on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could write a perl script to do this. Grab the info from the MySQL db and then use perl withe embedded shell commands to create the .htpasswd file(s). You can put this in a cron job so it's updated daily.

Seamless

4:41 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



Cheers for the reply Physics,

Maybe I should've been a bit more specific.

In other words the only thing that an .htpasswd file can contain is a list of usernames and encrypted passwords e.g.

username1:encryptedpw1
username2:encryptedpw2
username3:encryptedpw3
username3:encryptedpw3

Thanks for clarifying that for me.

I'm glad you have said that, I'm in the middle of writing a php script that will do something similar to what you mentioned and i didn't want it to be a waste of time.

Thanks once again.

Seamless

physics

5:56 pm on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cheers! Let us know how it works out.

Seamless

8:05 am on Dec 6, 2005 (gmt 0)

10+ Year Member



Will do.

volatilegx

10:58 pm on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I read that there is a way to get MySQL to "act" as the .password file. Here is a .htaccess code sample:

AuthName "Please enter a password to my site:"
AuthType Basic
Auth_MYSQLdatabase <DB NAME>
Auth_MYSQLpwd_table <USERNAME AND PASSWORD TABLE NAME>
Auth_MYSQLgrp_table <GROUP TABLE NAME>
Auth_MYSQL_nopasswd On
Auth_MYSQLpwd_field <PASSWORD FIELD NAME>
Auth_MYSQLuid_field <USERNAME FIELD NAME>
Auth_MYSQLgrp_field <GROUP FIELD NAME>
Auth_MYSQL_EncryptedPasswords on
order deny,allow
allow from all
require group Group1 Group2 Group3

Any comments on the workability of this? I haven't tested it myself.

Seamless

8:27 am on Dec 7, 2005 (gmt 0)

10+ Year Member



Thats looks interesting i'll give it a try,

The only thing that i don't get is the 'group' parts

e.g.

Auth_MYSQLgrp_table <GROUP TABLE NAME>
Auth_MYSQLgrp_field <GROUP FIELD NAME>
require group Group1 Group2 Group3

what details do i put into those fields? or can i leave them out?

volatilegx

3:44 am on Dec 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To be perfectly honest, I don't have the faintest clue :)

Seamless

8:42 am on Dec 8, 2005 (gmt 0)

10+ Year Member



ok, hopefully someone else will read this and let me know :D

Thanks anyway.