CodeIgniter Forums
Setting up a default username and password - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Setting up a default username and password (/showthread.php?tid=68459)



Setting up a default username and password - nullstrike - 07-13-2017

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:


Code:
class User_model extends Base_model
{
    public function __construct()
    {
        parent:: __construct();
        $this->user_add();
    }

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

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

    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


RE: Setting up a default username and password - skunkbad - 07-13-2017

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.


RE: Setting up a default username and password - kilishan - 07-13-2017

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.