CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Usernames

 



benchivers
Deleted

Jan 7, 2001, 9:06 AM

Post #1 of 5 (386 views)
Usernames Can't Post

I have created a script that creates a txt file which stores all of the usernames. How can I make it so if a person registers a username but it is already in the username txt file, the script displays "Username already taken please do the sign-up process again with a different username" and it doesn't overwrite the username already in the txt file. Any help required for this issue!



parham_m_s
journeyman

Jan 7, 2001, 11:48 AM

Post #2 of 5 (383 views)
Re: Usernames [In reply to] Can't Post

here's a simple solution:

Code
open(FILE, "$memberlistfile") or (FILE ERROR) 
flock (FILE, 2);
@memberlist = <FILE>;
flock (FILE, 8);
close(FILE);

foreach $memberlist (@memberlist) {
if ($memberlist =~ /\n$/) { chop $memberlist; }
if ($form_username =~ /^$memberlist$/i) {
print "Username already taken please do the sign-up process again with a different username";
}
}

i wrote this to be case-insensative, so if a username "John" is registered, "john" or "joHN" wouldn't be allowed to signup. If you want "John" and "joHN" and "JOHN" to be all different usernames, just take out the 'i'.

hope that helped :)



(This post was edited by parham_m_s on Jan 7, 2001, 10:50 AM)


benchivers
Deleted

Jan 7, 2001, 12:57 PM

Post #3 of 5 (381 views)
Re: Usernames [In reply to] Can't Post

Thanks panham! That has really helped!



SirAnvil
Deleted

Jan 7, 2001, 2:21 PM

Post #4 of 5 (379 views)
Re: Usernames [In reply to] Can't Post

Will this still work if the memberlist file has 2 columns one w/ the username and the other w/ the password?
Then if the user does already exist we can send them to input a pw and if not we can add them (wich would be easier)


SirAnvil


parham_m_s
journeyman

Jan 7, 2001, 4:17 PM

Post #5 of 5 (377 views)
Re: Usernames [In reply to] Can't Post

Siranvil, in your case, i wouldn't at all recommend that two people have the same username and different passwords. If one person, in the future decides to change their password, and picks the same password as another person with the same username, your database will end up messing up. What you could do is this (just a change to the above code):

Code
open(FILE, "$memberlistfile") or (FILE ERROR) 
flock (FILE, 2);
@memberlist = <FILE>;
flock (FILE, 8);
close(FILE);

foreach $memberlist (@memberlist) {
if ($memberlist =~ /\n$/) { chop $memberlist; }
($data_username, $data_password) = split(/\|/, $memberlist);
if ($form_username =~ /^$data_username$/i) {
print "Username already taken please do the sign-up process again with a different username";
}
}

i wrote this in mind that your username and password databases are separated using pipes (username|password).



(This post was edited by parham_m_s on Jan 7, 2001, 3:19 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives