473,796 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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 1795
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@localho st (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.19 1.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.c om 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@localho st (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.19 1.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
9755
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 for my friends and I, but I have run into an issue that I have often wondered about before. Any insight would be appreciated. The database contains semi-sensitive information. Not CC numbers, but think more like usernames/passwords to other...
2
2356
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 experienced C++ programmer. This has allowed me to see many potential areas where the security of a server can be compromised through loopholes in PHP. Granted, with the right knowledge these potential threats can be avoided. But I've just...
2
7949
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 authentication protocol requested by server; consider upgrading MySQL client in file.php on line 130"
1
931
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
2025
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 takes that \n as literal. Meaning, when I retrieve the records, they show up like "hello \n world".
10
1505
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 during the client connection sequence was upgraded in MySQL 4.1.1 to be very secure" Has anyone actually tested this by "sniffing" their packets during use? Also, does anybody know if this applies when using VB to connect using the connection...
9
2120
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, accented French characters, etc. I want to eliminate any potential for XSS or SQL injection attacks. My question - is it enough to pass all user input through the
0
6693
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 enabled/configured. I just want mysql to use a maximum of, let's say, 1GB of my /var partition The log is /var/log/mysql/
20
3028
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 code don't see my paswords. there is a solution? Thank you in advance. Mario.
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.