Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter an user name and password and log on?

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello. I have a question to ask. <br><br>I have a script, about 215 lines, that allows an user to input a user name, password, and several other pieces of information about him/herself. The script then adds all of the information to a database, a text file, and prints it out on the page. <br><br>I have gotten that to work fine.<br><br>Here is my question. Right now I have the script where there is one default password, and the user can enter the password, and depending on what the password is, route them to the proper place.<br><br>How do I write a sub-routine, or another program, to allow the user to input their user name and password on the front page, call up the text file with the information in it, and then depending on whether the password matches the user name, will route them accordingly.<br><br>I know that this has to be simple, it is on most pages, even this one. <br><br>If anyone could help, I would be very appreciative.<br><br>Thank you in advance.
 
so you're allowing users to set up individual passwords as opposed to one central pw? When they initialize their account, throw their individual passwords into the database (their username should be the primary key). Here's the sql way to do it- SELECT password FROM Data WHERE user=&quot;Tom&quot; (Tom is the person who's signing on)... you go through your database and query for that particular record- then you check the password entered in the database vs. the password given at the web form. If they're equal, grant access- if they're not, say so. I don't know what kind of database you're using and how you're accessing it, so I'm not sure if that helps at all.<br><br>I hope that answers your question- I'm not sure if I completely understood. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Sorry, I was not making myself clear on what I am doing.<br><br>I am not using an SQL database, but instead a .txt file for the database. The txt file is in a secure place, so I do not have to worry about that, but what my problem is that I do not know how to call a certain line of the database and check to see if that line matches another line.<br><br>Say I have two databases:<br><br>One is called user.txt and the other is called pass.txt, of course, the user.txt has the user name and the pass.txt has the password of each user name.<br><br>Then say, I have the following attributes for the user.txt file<br><br>vikter<br>kein<br>petre<br><br>as the different users that have signed up for my service. <br><br>Then, in the pass.txt file, I have the following attributes for the pass.txt file<br><br>bob<br>computer<br>Lrb5sk<br><br>as the passwords for the different users. So, the password for vikter would be bob, kein would be computer, and petre would be Lrb5sk.<br><br>Now, in Perl, how do I get my program to call the name vikter and check to see if the password entered into the form is, in fact, bob?<br><br>If anyone could help me, I would be very appreciative.<br><br>Thanks for all the help, and sorry for not making myself clear.
 
Usually, when I have made flat text file databases, I have included the username and password in the same file- that way you don't need to edit two different files. It's also 1 server hit instead of 2.<br><br>I'd set it up like this:<br><br>vikter&nbsp;&nbsp;&nbsp;&nbsp;bob<br>kein&nbsp;&nbsp;&nbsp;&nbsp;computer<br>petre&nbsp;&nbsp;&nbsp;&nbsp;Lrb5sk<br><br>You can create a hashtable when you parse the document. Parse it first by line- each line will be one entry into the hashtable. For each line, your tokens will be split by the tab. The first entry (the username) will go in the key, and the second entry (the password) will go in the value.<br><br>To check a user's password, match the input against the username. If that doesn't work, return a &quot;user name not found&quot; page. If it does, check their password against the corresponding value for that key in the hashtable. If the password is correct, grant access; if not, return a &quot;password not valid for corresponding user&quot; page.<br><br>Does that help?<br> <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Hello imotic.<br><br>Yeah, I a file where it has information such as <br><br>vikter : bob<br>kein : computer<br>petre : Lrb5sk<br><br><br>Where, the first piece of text is the user name, and the piece after the colon is the password, obviously. I have the program making a file like that, and a file that has all the names and a file that has all the passwords. With what you said, I think that I will use the txt file that has all the information in it, but only one problem, I do not quite, exactly know what you mean by parsing the file. Well I know what parsing it means, I just do not know how to.<br><br>Hmmmm. Thanks for all the help so far, but I am brand new at Perl. I have only started using it about 4 months ago, and I am not quite sure how to parse the text file. Would you use something such as:<br><FONT FACE=monospace><br>read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});<br>@cgiPairs = split(/&/,$buffer);<br>foreach $cgiPair (@cgiPairs)<br>{<br>&nbsp;&nbsp;($name,$value) = split(/=/,$cgiPair);<br>&nbsp;&nbsp;$value =~ s/\+/ /g;<br>&nbsp;&nbsp;$value =~ s/%(..)/pack(&quot;c&quot;,hex($1))/ge;<br>&nbsp;&nbsp;$form{$name} .= &quot;\0&quot; if (defined($form{$name}));<br>&nbsp;&nbsp;$form{$name} .= &quot;$value&quot;;<br>}<br></font><br>? I don't think that you would cause that only parses the stuff from the web form, and I am not sure how you would parse it from the txt file?<br><br>Or would you use something like:<br><FONT FACE=monospace> <br>open (FILE,&quot;&lt;&lt;data.txt&quot;);<br><br>while (&lt;FILE&gt;) {<br><br>$row = $FORM{'deleteuser'};<br>chop $row;<br><br>@fields = split (/\¦/, $row);<br><br>}<br>close(FILE);<br><br></font><br><br>Where $FORM{'deleteuser'} is the text field that you input the users name you want to delete. After that, I want the program to delete the entire line that has the user name on it, everything, including the password.<br><br>Could you post the code that tells me how to do this? If you could, I would be extremely appreciative.<br><br>Thanks for all the help so far. <br>Again, sorry for not clearifying what I needed. Thanks for the help so far though, its really helped.<br>
 
Sorry I forgot to mention this in the last message.<br><br>You can go to <A HREF=" TARGET="_new"> and see what I am trying to do with a live script.<br><br><br>The password to enter the site is morpheus, case sensitive.<br><br><br>You can add a user if you like, and don't worry about the extra/special priveledges, I will work on that later.<br><br>Thanks for all the help.
 
another thought......<br>If security is an issue, you can use 'crypt' to get a little better.&nbsp;&nbsp;It will keep the lazy hacker out. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top