I’m trying to use multidimensional array method to do the login check.
for example I have array below:
$multiuser['master'][0] = 'boss'=>'123456';
$multiuser['master'][1] = 'computer' => '636363';
$multiuser['admin'][0] = 'admin1' => '382382';
$multiuser['admin'][1] = 'admin2' => '323243';
How do I check user if they typed their username as ‘admin1’ or ‘boss’ is existed in this array and the password is matched with the username ‘admin1’/’boss’?
And I wanna to know it’s user group too. If boss username and password matched. How do I find it’s user group is under master.
This is not a good way to handle logins.
1) The structure of your array makes it hard to find the user. Of course, you could scan each array in
$multiuserand try to find the desired username, but as you try to add groups this will become harder and harder.You should make it easier to find the user, and look up the group from there. eg:
Now if you want to find a
$user, you just do$users[$user], and if it’s defined, it’s there. Then you could get the group from$users[$user]['group'], and so forth.2) You are using what appear to be plaintext passwords. Passwords shouldn’t be stored in plaintext, but at least hashed and salted. This is a very long subject, but here’s a starting point:
Password Hashing (PHP Security Consortium)
3) Regardless, you should ditch this idea of storing login info in a PHP completely and use a database. Storing user information in a flat file (not good), or a PHP file (worse) will make it very hard to manage going forward.
It might not look like a big deal since you have a handful of users, but it’s very messy.