Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

delete users

by titanic_fanataic (Acolyte)
on Dec 06, 2004 at 11:36 UTC ( [id://412623]=perlquestion: print w/replies, xml ) Need Help??

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

I have a database that looks like this:

username1|cryptedpass1
username2|cryptedpass2
etc...

and I would like to be able to delete a user from the database, how would I go about doing this?

Also, I have my users logging in via web form, and would like to give them a way to log out(for real) so that you have to login again instead of being able to push the back button

Thanks for the help,
Tylor

Replies are listed 'Best First'.
Re: delete users
by DaWolf (Curate) on Dec 06, 2004 at 12:18 UTC
    Hi.

    This looks as a flat text file to me, so I don't know if I exactly understood your question, but I really wanna help you, so let's start.

    If you were just representing a database, this would be easy, just do a simple SQL query:

    DELETE FROM your_table_name WHERE USERNAME = 'desired_user';

    If I was right at the first time and you just use a flat text file, take a look at Deleting a line out of text file for a start. That sould guide you fine.

    For your second question the answer is a little bit longer:

    Since your developing a system that has a web interface, a problem arise:

    What if the user just close the browser (by pressing ALT F4 or just clicking on that dreaded top right 'X' ;))? Since it's a hard thing to trigger an event when the user does this (I won't expand too much here since this is more a JavaScript thing) the user session (assuming that there is one) would remain opened and this is a security breach.

    So, the solution I've found out (and IMHO is the most used out there) is to do the following:

    1. When the user logs in store his session id and the current date and time on the database (or flat file).
    2. Each and every page entered by the user should do a check if the user data exists and update the database updating the date and time.
    3. Run a cron job that checks every XX minutes if the date and time of the user session is active and if is not (his date and time are over the XX minutes interval) delete his data from the db. So, the next page will see that the user data doesn't exist anymore and will redirect the user to (probably) the login page, so he starts the process all over again.


    Your logout routine (for the logout link) should just destroy the user session and delete his data from the database.

    There are a lot of issues on this question, but I hope I helped a little. Feel free to contact me if you have any questions.

    Best regards,

      Another way to handle the logging in and out is by setting a cookie:

      1. When the user logs in, use CGI to write a cookie containing their user name, possibly a code for their priviledges, and then an expire time.
      2. Each time you return to a server-side script, check the cookie. If it has expired, route them to the log in screen. If it has not expired, reset it and send them on their way.
      3. When they voluntarily log out, set the cookie's expire time to zero and return them to the log-in screen.

      It boils down to what you are most comfortable with, though the DB method has the advantage of allowing you to know who is logged on at any one time.


      —Brad
      "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton
Re: delete users
by b10m (Vicar) on Dec 06, 2004 at 11:58 UTC
      Actually I think Text::xSV might be more useful since it can hand delmiters other than the comma.
Re: delete users
by titanic_fanataic (Acolyte) on Dec 07, 2004 at 01:34 UTC
    I want to appologize for my innexperience with perl, I'm still trying to learn, but this is the best way to learn with hands on.

    I've included a link to a zip file HERE containing my current files, this should help make it easier to understand what I'm trying to acheive.

    I'm still not sure how to implement any of this code into my script. If someone would be willing to aid me by looking through my code and possibly even telling me where I need to make improvements on my code.

    Thanks for all of your help,
    Tylor
    skatemaster@shaw.ca

      I only glanced at the code...

      You'll need to open the adminpasswd.db or passwd.db file, find the line with the user and delete them. Here's one node, How do I delete/modify one line from test file ?, and I'm sure you can find others on the site.

      Frankly I'd follow the advice of the others on this thread and stuff it into a real database (MySQL or PostgreSQL are both good). Doing that will make your life a lot easier in the long run.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-24 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found