I am creating a log-in website where users use username
and password
to log-in and write their dairy. I have created a SQL database named 'diary'
which can be accessed using the following on my localhost.
$dbhost = 'localhost:3306';
$dbuname = 'diary';
$dbpass = 'guest123';
Inside the database diary
I created a table which stores 3 information of type VARCHAR
i.e.
user_id
password
(I just used plain-text for tutorial purpose)name
In the above example I provided the password and the name of the database in the following code, to have access to the database.
$conn = mysqli_connect($dbhost, $dbuname, $dbpass);
My question is, it is safe to hard-code the password of the database (eg. password of database diary
)? Considering an online application, if a hacker can hack into the server, then he will have full access to the database, because I have hard-coded the password in my program.
What I have assumed in the above example is that I have one database diary
that stores all the users log-in information.
Another alternative is that every user has their own database which is created when they sign-up. However, I believe that this option is not an ideal because all the databases of individual users are dis-joint and it may be difficult to manage.
I just need some explanations of this issues as I am new to this part, especially SQL. Say I have 1 million users, Which approach is better way to implement this example?