4
\$\begingroup\$

Any major security risks? And please don't get angry over my novice log system.

<?php
 function makesalt($lg)
 {
 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-'; 
 $sz = strlen( $chars );
 $str = '';
 for( $i = 0; $i < $lg; $i++ ) {
 $str .= $chars[ rand( 0, $sz - 1 ) ];
 }
 return $str;
 }
 function duelsha($th)
 {
 $tem = hash('sha512', $th);
 $tem2 = md5($tem);
 return hash('sha256', $tem2);
 }
 function shasalt($ht)
 {
 $salt = makesalt(30);
 return duelsha($ht . $salt) . '|' . $salt;
 }
 function mysqlsan($ss)
 {
 if (get_magic_quotes_gpc()) $ss = stripslashes($ss);
 return mysql_real_escape_string($ss);
 }
 function htent($st)
 {
 return htmlentities($st);
 }
 function sqlhtml($sm)
 {
 return htent(mysqlsan($sm));
 }
 function logs($tl)
 {
 $fh = fopen("server.log", 'w') or die("File error");
 fwrite($fh, $tl) or die("File error");
 fclose($fh);
 }
?>
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Feb 18, 2014 at 0:21
\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

You home brewed security hashes and such are a big NO. Please, check here and here for a good read regarding that. Also, please do not hash a hash, that can lead to collisions and should be avoided! Using a method such as password_hash() creates a salt for you, therefore you shouldn't have to make one on your own.

You're using mysql_real_escape_string() which is not the way to go. If possible, move away from that and onto mysqli or PDO.

And then your function htent() is sort of redundant. You don't have anything else in the function, so it shouldn't be needed.

answered Feb 18, 2014 at 1:48
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.