[php] comparing found username with string
I'm trying to build a server script to add local system users. Before creating a user the system must be sure that the user does not already exist. I'm trying to do this with the following code:
PHP Code:
PS: I'm using a copy of the file /etc/passwd.. This is only an example! |
Passthru is just supposed to display the output directly to the screen. You probably want to be using exec here. Also, your script sent shivers down my spine from a security standpoint. :)
|
I would do :
PHP Code:
use an user Array and loop its values |
strpos is dangerous in that context! suppose the following:
Someone attempts to sign up with the username "ack". In the /etc/passwd, there exists the following user: Code:
jack:*:..... remainder of line /^$username:/, though you would want to make sure username contains no colons first (not that they should be there in a username anyway) |
In this case, better is to do a strict string compare
PHP Code:
|
All times are GMT -5. The time now is 09:18 PM. |