• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting up a default username and password

I have a small web application designed for a small business where the users are only 2 but with different user privilege.
My idea is after the user logged in using the default user and password he will be redirected to a page where he will be updating his password and username. If the user will not update it then it will not be able to navigate through admin dashboard.

Here's my code:

class User_model extends Base_model
    public function __construct()
        parent:: __construct();

    public function user_add()
        if ($rows = $this->count_row() < 2) {
            $data = array(
                    "user_username" => "admin",
                    "user_userpass" => "default",
                    "user_type" => "admin"
                    "user_username" => "normal",
                    "user_userpass" => "default",
                    "user_type" => "standard"

            for ($i = 0; $i < 2; $i++) {
                $this->add('user', $data[$i]);
            return true;

    public function count_row()
        $result = $this->db->count_all('user');
        return $result;

Would these be a good practice or shall I only asked username for first-time logged in

Add a field in the user table called last_login, where you store a timestamp every time a user logs in. Since a new user needs to update their password on first login, this is how you can check that. After the password change, set the timestamp. Anytime you want a user to change their password, delete the timestamp.

You could also create a flag in the users table called 'force_reset' that, if 1, would tell you they need to reset their password.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.