views:

122

answers:

4

I am wondering what the best practices are for creating non-loggable accounts. On StackOverflow, there is a Community Wiki account that I'm assuming can't be logged into.

How should I go about scripting for non-loggable accounts? If there is an account that I don't want to be accessible, should I set parameters like you can't log into accounts with IDs less then 0? Or should I just manually define the IDs that cannot be logged into in the configuration ID? or is there a better way?

+4  A: 

To me you should use a flag in the account data, in order to set or revoke the logging capability.

This capability can be enforced with a query at sql level quite easily.

A query like:

select wathever from user where loggging=1 and user="aUser" and passwd="password"

can do the trick.

Answering your comment: Maybe using a colum appears not efficent to you but you have to consider the pro:

  • You have the information about your users in a single layer, not scattered around beetween database, configuration files, or wathever

  • You can revoke or grant the logging capability to any account without having to modify configuration files

Eineki
+2  A: 

You can set a "flag" on your user table:

loggable      int(1)       default 1

Then you can check on your script:

//... data retrieve login ...
if($userRow['loggable'] == 1) {
    //User can login, do stuff
} else {
    //Tell him that he can't login
}
Nathan
But wouldn't adding an entire column to simply get rid of 1 or 2 users be inefficient?
Chacha102
If you already have roles, adding a "no-login" role sounds best to me. Otherwise, I can't imagine it being terribly innefficient to add one boolean for "loggable". I suspect that you'll end up with a number of different permissions for each user anyway. Basing it on the db id can work too, but has few advantages, imo.
jsight
If you put that as an answer I'd mark it.
Chacha102
If it will not change always, like an administration panel where the admin would "disable" some users, you can hardcore it on an array, or an external xml file, but by doing this you'll need to edit the code manually to get rid of another user if you want to.
Nathan
A: 

Add a "loggable" field to accounts. It's scalable in case you end up having lots of non-loggable accounts.

slipbull
A: 

You could make an empty password be non-loggable.

To extend Eineki's SQL:

select whatever from user where loggging=1 and user="aUser" and
    passwd="password" AND passwd IS NOT NULL
creuzerm