473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

[mySql] How to keep passwords secure

I just finished writing my first php script that manipulates a simple
shopping cart on a mySql database. I started with an example I found
on the web. The example hardcodes the database server, name, user, and
password in a php include file. This file is then included in every
php script that needs access to the database.

How do I make this scheme secure? I assume this is ok as long as this
file remains inaccessible on the webserver. How to guard against
access?

Dec 10 '06 #1
7 1751
Skijor wrote:
I just finished writing my first php script that manipulates a simple
shopping cart on a mySql database. I started with an example I found
on the web. The example hardcodes the database server, name, user, and
password in a php include file. This file is then included in every
php script that needs access to the database.

How do I make this scheme secure? I assume this is ok as long as this
file remains inaccessible on the webserver. How to guard against
access?
you could place it outside the Document Root or within a protected
directory.
Dec 10 '06 #2
you could place it outside the Document Root or within a protected
directory.
I did just that and I created an .htaccess file in the directory to
allow apache to protect it. I'm still a little insecure tho'. I can't
seem to get to the directory using browser so why the need to protect
it with .htaccess? My guess is that there will always be the potential
to get into this directory via url hacks. Also I was able to dowload
the file via ftp from the command line. How to stop that?

Dec 10 '06 #3

Skijor wrote:
you could place it outside the Document Root or within a protected
directory.
sorry. I mean I did both. Moved it outside the Document Root AND
inside a directory protected with .htaccess. Is this overkill?

Dec 10 '06 #4
>you could place it outside the Document Root or within a protected
>directory.

I did just that and I created an .htaccess file in the directory to
allow apache to protect it. I'm still a little insecure tho'. I can't
seem to get to the directory using browser so why the need to protect
it with .htaccess?
PHP will occasionally break (when you're in the middle of upgrading it)
and the web server may at that time serve up .php files without running
them. By putting the file outside the document root, you're protected
two ways:

- If PHP isn't working, you can't serve the file containing the
file because it's outside the document tree.
- If PHP *IS* working, you won't serve the file, it will just
be run as PHP.

Also, the file should be readable by the user running PHP but not by
all users.
>My guess is that there will always be the potential
to get into this directory via url hacks.
That would be a pretty serious bug in Apache.
>Also I was able to dowload
the file via ftp from the command line. How to stop that?
Were you able to download the file via *Anonymous* ftp?
If so, you've got a big problem. If it's via non-anonymous FTP,
keep your password secure.
Dec 10 '06 #5
In addition to keeping your password secure, it's important only to
give the database user that you are using access the database from the
web the minimal amount of privileges it needs to work. This for the
most part your web database user should only have SELECT, UPDATE,
INSERT and DELETE. For things like a shopping cart you should even go
as far as locking things down on a per table basis.

For example, let's say you have a table with all your products in it,
the web user shouldn't have the ability to delete, update or insert
into this table. The web user is only going to list and view you
products so he only needs access to SELECT from this table. (This also
can HELP protect against SQL injection attacks)

On more thing to do is make sure that the web user you are giving
access to has a host name that it should be connecting to. For example,
webuser@localhost (and not webuser@%). This again would restrict people
from access your database from a server other than the one your
database is on. If your webserver and database are different machines,
do the same thing. For example: your web server's IP is
192.191.190.189, your database accounts that are coming from the web
server should be "we*****@192.191.190.189".

This can help minimize any damage that could be done should your
database user/password be compromised. This however is very unlikely if
you take the measure described above. (But if you are offsite and
uploading files via standard FTP, it is being sent in plain text). It
never hurts to be have redundant security measures.

Gordon Burditt wrote:
you could place it outside the Document Root or within a protected
directory.
I did just that and I created an .htaccess file in the directory to
allow apache to protect it. I'm still a little insecure tho'. I can't
seem to get to the directory using browser so why the need to protect
it with .htaccess?

PHP will occasionally break (when you're in the middle of upgrading it)
and the web server may at that time serve up .php files without running
them. By putting the file outside the document root, you're protected
two ways:

- If PHP isn't working, you can't serve the file containing the
file because it's outside the document tree.
- If PHP *IS* working, you won't serve the file, it will just
be run as PHP.

Also, the file should be readable by the user running PHP but not by
all users.
My guess is that there will always be the potential
to get into this directory via url hacks.

That would be a pretty serious bug in Apache.
Also I was able to dowload
the file via ftp from the command line. How to stop that?

Were you able to download the file via *Anonymous* ftp?
If so, you've got a big problem. If it's via non-anonymous FTP,
keep your password secure.
Dec 11 '06 #6
very helpful. Didn't think to restrict write privilages to the cart
only. Such an obvious fact to overlook. As far as checking webser
IP's my database and webserver are hosted commercially and I don't
think database users will be arriving from the same webser all the
time.
mm*****@gmail.com wrote:
In addition to keeping your password secure, it's important only to
give the database user that you are using access the database from the
web the minimal amount of privileges it needs to work. This for the
most part your web database user should only have SELECT, UPDATE,
INSERT and DELETE. For things like a shopping cart you should even go
as far as locking things down on a per table basis.

For example, let's say you have a table with all your products in it,
the web user shouldn't have the ability to delete, update or insert
into this table. The web user is only going to list and view you
products so he only needs access to SELECT from this table. (This also
can HELP protect against SQL injection attacks)

On more thing to do is make sure that the web user you are giving
access to has a host name that it should be connecting to. For example,
webuser@localhost (and not webuser@%). This again would restrict people
from access your database from a server other than the one your
database is on. If your webserver and database are different machines,
do the same thing. For example: your web server's IP is
192.191.190.189, your database accounts that are coming from the web
server should be "we*****@192.191.190.189".

This can help minimize any damage that could be done should your
database user/password be compromised. This however is very unlikely if
you take the measure described above. (But if you are offsite and
uploading files via standard FTP, it is being sent in plain text). It
never hurts to be have redundant security measures.

Gordon Burditt wrote:
>you could place it outside the Document Root or within a protected
>directory.
>
>I did just that and I created an .htaccess file in the directory to
>allow apache to protect it. I'm still a little insecure tho'. I can't
>seem to get to the directory using browser so why the need to protect
>it with .htaccess?
PHP will occasionally break (when you're in the middle of upgrading it)
and the web server may at that time serve up .php files without running
them. By putting the file outside the document root, you're protected
two ways:

- If PHP isn't working, you can't serve the file containing the
file because it's outside the document tree.
- If PHP *IS* working, you won't serve the file, it will just
be run as PHP.

Also, the file should be readable by the user running PHP but not by
all users.
>My guess is that there will always be the potential
>to get into this directory via url hacks.
That would be a pretty serious bug in Apache.
>Also I was able to dowload
>the file via ftp from the command line. How to stop that?
Were you able to download the file via *Anonymous* ftp?
If so, you've got a big problem. If it's via non-anonymous FTP,
keep your password secure.
Dec 14 '06 #7
>very helpful. Didn't think to restrict write privilages to the cart
>only. Such an obvious fact to overlook. As far as checking webser
IP's my database and webserver are hosted commercially and I don't
think database users will be arriving from the same webser all the
time.
If you have a public IP address, you can pretty much figure that
there will be attempts to log in to MySQL on that server at least
once a day - whether you've actually got a MySQL server or not. If
they find one that will let them try to log in, they'll try harder.
Dec 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Hello all. I'm currently working on a new site that encompasses the registration of members. The registration is taking place through PHP interaction with MySQL. The site is just going to be...
2
by: Xizor | last post by:
Ok, I'm new to PHP and MySQL. I've been going through tutorials, reading the documentation, and looking through web sites. PHP to me seems great! With MySQL it seems even better. However, I'm an...
2
by: yzzzzz | last post by:
Hi I just upgraded from MySQL 4.0.something to 4.1.1 (alpha). When I try to connect to MySQL in a PHP script, I get the following error: "mysql_connect(): Client does not support...
1
by: Jordy | last post by:
Environment: Sun servers running solaris 2.8 Php 4.3.6 Apache 1.3.29 Mysql 4.1.1 phpMyAdmin 2.6.0-alpha1 phpAds 2.0 PhpMyadmin and phpAds don't succeed to connect the MySql database when
1
by: el chupacabra | last post by:
I'm using mysqldb module and python 2.4. I'm a newbie. Thanks in advance. 1. Output desired: "hello" "world" I know that MySQL takes \n and \t and what not. But my python script, it...
10
by: Bob Hollness | last post by:
OK. The below text is from the MySQL website. "When you connect to a MySQL server, you should use a password. The password is not transmitted in clear text over the connection. Password handling...
9
by: Harold Crump | last post by:
Greetings, I have a fairly vanilla PHP web application that stores and retrieves data in a MySQL database. Users will be adding a lot of special characters such as single and double quotes,...
0
by: Chrom_ | last post by:
Mysql is filling my /var partition because the log limit doesn't seem to be respected. I've tried many different settings in /etc/mysql/my.cnf but nothing works. Logrotate is not...
20
by: _mario.lat | last post by:
hallo, I use PHP and I'd like to not write in hardcoded way password and login to access to mysql. how to not write password in code for access to mysql? How can I do? I'd like that who see my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.