Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Auth System

by emcb (Beadle)
on Dec 23, 2001 at 08:45 UTC ( #134019=perlquestion: print w/replies, xml ) Need Help??

emcb has asked for the wisdom of the Perl Monks concerning the following question:


Im creating an authentication mechanism on my intra using perl/win2k. So far i am going to use a text-file to store the users information. Heres what the file looks like.

# passwd.ini user1|pass1||some|other|stuff user1|pass1||some|other|stuff user1|pass1||some|other|stuff
And so on... what i think i should do is extract them into arrays like %user/pass/email/some/other/vars, but i dont know how. Any help would be great so i can get this running.



Edit kudra, 2001-12-23 Added markup

Replies are listed 'Best First'.
(crazyinsomniac) Re: Auth System
by crazyinsomniac (Prior) on Dec 23, 2001 at 09:13 UTC
    By "intra" I'd guess you mean intranet, but in any case, it has no bearing here whatsoever. My question to you is, What made you pick this format (if you have no idea how to parse it, why'd you pick it)?
    # passwd.ini user1|pass1||some|other|stuff user1|pass1||some|other|stuff user1|pass1||some|other|stuff
    "what i think i should do is extract them into arrays like %user/pass/email/some/other/vars"

    Why do you think that?

    Arrays %user...? I suggest you read perldata until you understand the basic perl data structures. After that, I sugguest you head on to perlfunc and look at perlfunc:split... perlsyn is always a good read ...

    IMHO, that's more than enough reading material to get you on your way and beyond.


    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Re: Auth System
by jlongino (Parson) on Dec 23, 2001 at 10:54 UTC
    As crazyinsomniac points out you might want to become a bit more familiar with the Perl array and hash data structures. %varname denotes a hash, @varname an array. If you were generating a list of all users or performing some task(s) for more than one user, then using an array or hash would be appropriate. Why store all that data you're not even going to use?

    However, if what you are trying to do is to perform some task if a user is in your authentication file, you probably don't need either structure. The following code illustrates this approach:

    use strict; use warnings; my $searchfor = "somebody"; my ($login, $pass, $email, $some, $other, $stuff); open PASSWD, "<passwd.ini"; while (<PASSWD>) { if ((split/\|/)[0] eq $searchfor) { chomp; ($login, $pass, $email, $some, $other, $stuff) = split /\|/; last; } print "nomatch: ", (split/\|/)[0], "\n"; } if ($login) { # match was found. 'print' verifies we got the right stuff. print "match found: $login, $pass, $email, $some, $other, $stuff\n" +; # do whatever else . . . }
    Contents of file: passwd.ini
    nobody|nopass||some1|other1|stuff1 anybody|anypass||some2|other2|stuff2 somebody|somepass||some3|other3|stuff3 everybody|everypass||some4|other4|stuff4
    Resulting output:
    nomatch: nobody nomatch: anybody match found: somebody, somepass,, some3, other3, stu +ff3


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://134019]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2023-06-05 21:05 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.