1

I am storing passwords after bcrypting but user email ids as a plain text(without encrypting), because I want to send newsletters to that email ids regularly. I have got two questions?

  1. How to secure the database so that email ids as the plain text in the database can be secured from hackers?

  2. Is there any way to check the particular database table is only accesed by my web form not from outside?

note:I am new to database.

NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
VDN
  • 85
  • 1
  • 9
  • 4
    If someone can see your raw database, you're doing something wrong already. – woz May 16 '13 at 17:02
  • I am new to database,trying to understand. can you explain more about this? – VDN May 16 '13 at 17:05
  • You just have to practice all round good security. Eg, see http://www.acunetix.com/websitesecurity/webserver-security/ (curiouslly that page doesnt mention firewalls, probably because its obvious should have a well configured firewall on all servers) – barryhunter May 16 '13 at 17:08

2 Answers2

1

1- If you really want to encode the emails, and need to decode them in the future, your best bet is to look at the MySQL encryption functions like ENCODE() and DECODE(). First you need to set up a "salt". This is like a secret code. It can be the same for every record, like this:

SELECT DECODE(email, 'mysecretsalt') FROM Table WHERE id=1

Or, you can make the salt part from a code and another field in the table, like this:

SELECT DECODE(email, CONCAT('mysecretsalt', id)) FROM Table WHERE id=1

2- Set up a specific user in your database that ONLY has access to that specific table and ONLY has INSERT privileges for when you are adding records, and then another user that only has SELECT privileges when you are retrieving the records. Also, lock those users down to the "localhost". If a hacker gets one of those, they can't do much.

Also, when you receive the email from the customer in the form of a request variable (GET or POST), to protect from SQL injection attacks, either escape characters (in PHP, you could use mysqli_real_escape_string()) or simply get rid of all characters that don't belong. In PHP, it would look like this:

$email = preg_replace('/[^A-Za-z0-9\\.@-_]/', '', $email);

That's the way I like to do it.

jon__o
  • 1,509
  • 13
  • 14
0

There's nothing wrong with storing emails in plaintext. Even if accessed they don't allow the attacker to access the accounts (provided the authentication works correctly). There's no reason to encrypt them unless you have some very specific requirements we don't know about.

If you want to secure your database in general:

  • read the database documentation
  • if you have multiple services / scripts accessing the data, make sure they have separate accounts and have access only to the data they need to access
  • make sure your database backups are at least as secure as the database itself
  • limit the source hosts (possibly when setting up users) for the accounts to only allow connections from your web frontend, or if you're running on the same host maybe you can disable everything apart from loopback (bind the database to 127.0.0.1)
  • ... loads of other things are possible, but start from the basics... you'll find more ideas in the documentation, I'm sure
viraptor
  • 33,322
  • 10
  • 107
  • 191
  • 1
    If they get the email id's from the database they can use it for sending spam emails to those id. I am worried for that. – VDN May 16 '13 at 17:10
  • 1
    well you have to secure the database, so its unlikly they can get access to the database – barryhunter May 16 '13 at 17:13
  • This may not be a popular view... but in today's world I don't think anyone would notice (unless it was targeted spamming trying to take your users over) - hundreds of spam messages a day are a norm to me - they get filtered out automatically. If you get your service hacked and someone gets the list of your users... I'd say that them being spammed is not one of the biggest issues. Just ensure as much as you can that this doesn't happen. – viraptor May 16 '13 at 17:15
  • Can you give any online link where I can learn about this database security? – VDN May 16 '13 at 17:27