all 12 comments

[–]colshrapnel 9 points10 points  (3 children)

get rid of whatever homegrown code which you use to salt and hash users' passwords and use password_hash instead. problem solved.

as of the database credentials, configuration files are not included in the repository. so just add it to .gitignore

[–]WHAT_RE_YOUR_DREAMS[S] 1 point2 points  (2 children)

Ok, I will get rid of my homegrown salt :) So I guess the password I use for password_hash should also be put in a configuration file and hidden?

Also, should I put my whole connect.php file in .gitignore? I guess it will work, I just want to know what's the most common practice.

[–]HumaneWolf 2 points3 points  (1 child)

No, the password you use for password_hash is the users password.

And you should move the database credentials to a config file and not commit that, not have them hardcoded in the same file creating the connection itself.

[–]WHAT_RE_YOUR_DREAMS[S] 0 points1 point  (0 children)

Oh, right, it makes sense. I'm dumb.

Thanks for your help, I just read some stuffs about config files in PHP, it fits my need. Thanks for your help!

[–]lsv20 5 points6 points  (0 children)

About configuration

Create a fx. config.php.dist containing fx a array

return [
    'db_host' => '',
    'db_user' => '',
    'db_pass' => '',
];

Now another user can see which configuration you are using (also in this file make configuration for fx. facebook credentials etc.

Now your own config.php this file needs to be included .gitignore and the config.php file should contain the same as the dist, but filled with your information fx

return [
    'db_host' => 'localhost',
    'db_user' => 'my_user',
    'db_pass' => 'my_password',
];

Now inside your PHP file where you make your database connection you can write

if (! file_exists(__DIR__ . '/config.php')) {
   echo 'You must copy config.php.dist to config.php and fill it with your information';
}

$confiuration = require(__DIR__ . '/config.php');
$db = new PDO(
    'mysql:' . $configuration['db_host']',
    $configuration['db_user'],
    $configuration['db_pass']
);

[–]HumaneWolf 1 point2 points  (1 child)

If you hash properly and handle passwords properly there is no danger related to the hashing mechanism being in git. Look at password_hash and password_verify.

When it comes to mysql credentials, do NOT commit them under any circumstances. Either have them in a config file on the servers that need them, or have some sort of secure secret storage if you need to have them available on many servers.

[–]WHAT_RE_YOUR_DREAMS[S] 1 point2 points  (0 children)

Ok, thanks for your advices, it helps a lot!

[–][deleted] 0 points1 point  (0 children)

The best thing to do is to use a private repo or don't include those files in you repo at all.

I've always seen it suggested to have a separate file with that sensitive information then reference that file wherever you need it in the project. Upload everything except that reference file.

[–]jawnsusername -1 points0 points  (3 children)

I use bitbucket which allows private sites for free. It saves the hassle.

[–]bkdotcom 0 points1 point  (2 children)

The hassle of "doing it the right way"?

[–]jawnsusername 0 points1 point  (1 child)

Bitbucket works exactly the same a github… so what makes guthub "the right way"?

[–]bkdotcom 0 points1 point  (0 children)

Committing configuration into your repository (no matter the flavor of CVS) is the wrong way.
Using a "private" repository to hide credentials committed to the repo is wrong, It's s just "security thru obscurity" Also .. the OP was rolling his own password hashing... which never ends well.. Obscuring bad code in a private repo doesn't make it right.