If you want to protect some directory / folder in cPanel by placing a username password and you wanted to prevent public access for it, cPanel has inbuild option to do that.
cPanel > Directory Privacy
Press Edit on your required Folder.
Tic on the check box and press Save.
Then your Directory will be protected.
After that you will get a place to give a new username and password there.
Give your username and password, thats all. Now you can’t access via web browser to that directory without giving that login details.