Q:

Randomly generate pw as a default for new users and then let them change password later on using php

Hello everyone I am new to web dev and working on my personal project using php. I successfully generated 9 digit default pw for new users. I would like to let admin have visibility for the default 9 digit pw for new users. However, I don't want admin to have visibility for newly changed user pw. Let's say that a new user changes his password form 123456789 to jk1234. And I would like to save the password as jk****. But I was not able to use code below because it masks original 9-digit pw too.
    $masked =  str_pad(substr($number, -4), strlen($number), '*', STR_PAD_LEFT);

How should I solve this problem.

Thanks!!
edit!!!! Code below works perfectly(check if email address and pw is correct)
    if(isset($_POST['email']) && isset($_POST['password'])){
        $email=mysqli_real_escape_string($con,$_POST['email']);
        $password=mysqli_real_escape_string($con,$_POST['password']);
        $res=mysqli_query($con,"select * from employee where email='$email' and password='$password'");
        $count=mysqli_num_rows($res);
        if($count>0){
            $row=mysqli_fetch_assoc($res);
            $_SESSION['ROLE']=$row['role'];
            $_SESSION['USER_ID']=$row['id'];
            $_SESSION['USER_NAME']=$row['name'];
            $_SESSION['DEPARTMENT']=$row['department_id'];
            header('location:index.php');
            die();
        }else{
            $msg="Please enter correct login details";
        }
    }

However, After I hashed the password like below

And changed my code using password_verify, it does not work properly
(checks if my password is "$2y$10$JMaBasEsYINcxA3zbxNOguYW2aWSf1THmOB7J7kj8nw7KL5g64Qwm" or not)
Can you please tell me what the problem is?
    if(isset($_POST['email']) && isset($_POST['password'])){
        $email=mysqli_real_escape_string($con,$_POST['email']);
        $password=mysqli_real_escape_string($con,$_POST['password']);
        $res=mysqli_query($con,"select * from employee where email='$email' and password='$password'");
        $count=mysqli_num_rows($res);
        if($count>0){
            $row=mysqli_fetch_assoc($res);
            $_SESSION['ROLE']=$row['role'];
            $_SESSION['USER_ID']=$row['id'];
            $_SESSION['USER_NAME']=$row['name'];
            $_SESSION['DEPARTMENT']=$row['department_id'];
                if(password_verify($_POST['password'],$password)){
                    session_regenerate_id();
                    header('location:index.php');
                    die();
                }
        }else{
        $msg="Please enter correct login details";
      }
    }

A:

Passwords should never be stored in plain-text or be in any state that it can be decrypted at any time. This is really bad practice. I also recommend your passwords consist of words, phrases, special characters as well as numbers, for better security.
Please consider the use of password_hash() and password_verify() as an absolute minimum in your project.
Passwords should only be known by the user intended for access to that account. You should allow your users to select their own passwords and provide a secure way of resetting their password themselves should they ever lose access.
As passwords should not be able to be decrypted, the usual process would be:

User enters their password
You encrypt and process their input, and then compare the encrypted hash against the hash you have stored.

There should never be any reason that an "admin" should require a users password. Your project could allow "admins" to perform most actions a user could, without login in as them as they would be considered to have "escalated privileges".
I cannot provide an answer to your original question, as it's not beneficial to you or the SO community to do so however, the advice provided I hope will help steer your project in the right direction.
Links:

Why is password hashing considered so important?

A very basic login script tutorial

