I already made a site for a company that sells clothing and jewellery using an offsite paypal basket. It has a very basic bespoke cms that at the moment only allows the site owner himself to log in. Whilst logged in he is able to add/remove/edit products, and manage a basic news feed on the front page of the site.
I now want to expand the site to allow non-admin users to register, and for them to be able to do things like post comments on the news feed, and also to be able to post on a forum etc, but do not want them to have access to the stuff that the admins can do.
My initial thoughts were to use something like the following:
public function validate_user()
{
$username = trim($this->input->post('username'));
$password = trim($this->input->post('password'));
$password_md5 = md5($password);
//query database searching for user
$this->db->where('username', $username);
$query = $this->db->get('users');
//if user found in database, set session info
if ($query->num_rows() == 1) {
$result = $query->row();
$output['username'] = TRUE;
//check if password correct
if ($result->password == $password_md5) {
$output['password'] = TRUE;
if ($result->admin) {
$admin = TRUE;
} else {
$admin = FALSE;
}
//set session data for user including validated status
$data = array(
'id' => $result->id,
'username' => $result->username,
'fname' => $result->fname,
'lname' => $result->lname,
'admin' => $admin,
'validated' => TRUE
);
$this->session->set_userdata($data);
} else {
$output['password'] = FALSE;
}
} else {
$output['username'] = FALSE;
}
return $output;
}
I am conscious of the fact that storing a boolean administrator status value in the session data could be a bad idea for security reasons, and could be exploited. I would be grateful for some advice on whether I'm heading in the right direction with this, and for any suggestions on how I could accomplish a system like the one I've described above.
Thanks in advance.