1

Currently my database user and its password are pretty easily to guess, eg.

database user: dbadmin

database pwd : super + companyname

What and how to generate a secure a secure database password? Using md5 or sha1??

What are the things that I need to pay attention to secure my database?

I am using php, thanks

6 Answers 6

4

php shouldn't matter when choosing passwords, or usernames, no programming language should have any real effect on it. I've always generated passwords for any service with pwgen -syB. For something like a databse, where you're sticking the password in a file, and won't have to actually remember it, I'd probably use pwgen -syB 10, or 20 however.

3
  • 1
    -s seems to override -y, at least on my system. I get no symbols in the passwords generated with pwgen -ysB. Maybe -syB will work better for you. It does for me.
    – Thomas
    Jul 25, 2009 at 15:05
  • yep. you're correct. I remember the flags, but not the order.
    – Cian
    Jul 25, 2009 at 15:19
  • There is also secpwgen. Name suggests that it is more secure. Jul 26, 2009 at 5:09
1

The choice of the hashing algorithm (SHA-1 or MD5) does not affect the strongness of the password itself. It is only used by the database server to store a string which represents your password.

If you protect the place where your passwords are stored physically (which is generally a good idea) it does not matter if you choose SHA-1 or MD5.

I would choose SHA-1 because it is more secure than MD5 nowadays, but in this special situation it should not matter.

1

As a side note, securing database should also consist of what parts of the whole database the user accessing has access to and what sort of actions she can perform on it. So, think your grant's in advance.

2
  • 1 user perform all actions, is it secure?
    – bbtang
    Jul 25, 2009 at 16:23
  • It really depends if they need to preform them all. Does the web user need to write to the database? Do they need to be able to change the schema. If so, then it's right to give them the permissions they need. If they don't, then remove them. Jul 25, 2009 at 16:43
1

It's probably more important what database you're using. As you don't say, I'll give generic advice. If you comment, I'll try to give more specific help.

There should be a couple of areas you should look at. First of all, if the database is on the same host as the application, configure the database to only bind to the loopback interface. This means that the database is not accessible over the network. You would have to be on the local machine to access it. This will not prevent local users or someone who has hacked into the machine. If the database is on a remote server, look at restricting access from just the application server. If you don't trust the network between the hosts, investigate using SSL for the connection.

Secondly, check your permissions that are granted to individual users. Most database servers have a very flexible set of permissions that you can grant or revoke from individual servers. If you only need a user to read from the database, only grant them SELECT privileges. There shouldn't really be any reason why the webapp needs the ability to change the schema, so don't give them the ability to use CREATE, CHANGE or DROP.

If you can't access the database remotely, there is no benefit in using a strong password for your user.

One thing you should be very careful about is auditing your PHP to prevent SQL injection attacks against your database. This is easy to forget in PHP as it doesn't do much to help you. Other languages tend to use placeholders, which make this type of attack almost irrelevant.

4
  • Thanks. I need to explore all the things you have mentioned. My database is on remote server, thus I am quite worried :(
    – bbtang
    Jul 25, 2009 at 16:24
  • Do you trust the network? Is it all under your control? Do you control the remote database server? Jul 25, 2009 at 16:43
  • yup.. full control. But I am new to this, I am very afraid I would screw the things. Hope you could give some tips.
    – bbtang
    Jul 25, 2009 at 17:31
  • As long as the database isn't accessible from the internet, you should be fine. You can configure the database to restrict access from your app server, both in the access control and in a firewall if you're paranoid. Add SSL and you should be good. If your webapp and your database is behind a firewall, you shouldn't need to worry. Jul 25, 2009 at 18:50
0

I use Diceware to choose strong passwords. You should as well.

http://world.std.com/~reinhold/diceware.html

0

One thing you should be very careful about is auditing your PHP to prevent SQL injection attacks against your database. This is easy to forget in PHP as it doesn't do much to help you. Other languages tend to use placeholders, which make this type of attack almost irrelevant.

Using prepared statements (with PDO) helps to prevent from SQL injection.

If you can't access the database remotely, there is no benefit in using a strong password for your user.

What if someone gains access to the database server itself? If you use a strong password he/she has to become root to have unrestricted access to the data which are stored in the databases, if the server is configured reasonable.

You must log in to answer this question.