PDA

View Full Version : [SQL]Little problem


ZeniMax
30.07.2007, 07:10
I dont know why but when im trying to SELECT answer1 and answer2 from user_auth allways its blank result!.


$query = "SELECT account, password, answer1, answer2 FROM user_auth WHERE account = 'account'";
$query_verificar = mssql_query ($query);
while ($row = mssql_fetch_array($query_verificar))
{
$respuesta1 = $row[answer1];
$respuesta2 = $row[answer2];
echo "Answer1: $respuesta1<br> Answer2: $respuesta2";
}

Phantom2005
30.07.2007, 10:00
EDIT:
Sorry my mistake. It's just for the fact it's binary.
Binary cannot be displayed just like passwords.

Guaresnay
30.07.2007, 14:49
There is no way for you to see passwords from there.

ateh
30.07.2007, 19:43
function Mbin2string($binstr)
{
$out = "0x";
for($q=0; $q < strlen($binstr); $q++) {
$w = dechex(ord($binstr[$q]));
if(strlen($w)==1) $w = '0'.$w;
$out .= $w;
}
$out = strtoupper($out);
$out[1] = 'x';
return $out;
}


put your binary result as parameter to this function and you will see the hex string.

Kenjiro
30.07.2007, 19:51
It's just:

print ( bin2hex ( $answer1 ) );

ZeniMax
31.07.2007, 02:12
I dont want to see the password (becaouse its impossible). I only want to see the row info. But my question its why all the time gives blank results.

PS: I use this to compare function (its a page for change password, I add to compare the $_POST['answer1] to compare with the answer1 in user_auth.

$answer1_e = '0x' . bin2hex($respuesta1);

Guaresnay
31.07.2007, 03:01
I dont want to see the password (becaouse its impossible). I only want to see the row info. But my question its why all the time gives blank results.

PS: I use this to compare function (its a page for change password, I add to compare the $_POST['answer1] to compare with the answer1 in user_auth.

$answer1_e = '0x' . bin2hex($respuesta1);
In that case, ask for old pass, encrypt it, then u check if that password is the same that the password stored using the binary function for SQL..
its like..

$query = "SELECT account, password FROM user_auth with (nolock) WHERE account = '".$_POST['account']."' AND password = CONVERT(binary, ".encrypt($_POST['oldpass']).")";
$link = mssql_query ($query);
if(!mssql_num_rows($link)){
$error = "wrong password";
}

FidoW
31.07.2007, 11:40
In that case, ask for old pass, encrypt it, then u check if that password is the same that the password stored using the binary function for SQL..
its like..

$query = "SELECT account, password FROM user_auth with (nolock) WHERE account = '".$_POST['account']."' AND password = CONVERT(binary, ".encrypt($_POST['oldpass']).")";
$link = mssql_query ($query);
if(!mssql_num_rows($link)){
$error = "wrong password";
}

SQL injecction possible with that query... be carefull...
WHERE account = '".$_POST['account']."' AND

' OR 1=1; --

ZeniMax
31.07.2007, 12:55
Yes I know but for now its for test. After I test I Put this L2cp modded function:

function seguridad1($strh) {
$banwordshh = array ("'", ",", ";", "--", "%", "-", "SELECT", "DROP", "UPDATE", "QUERY", "%", "IN", "UNION, "\"", "'");
if ( eregi ( "[a-zA-Z0-9]+", $strh ) ) {
$strh = str_replace ( $banwordshh, '', strtolower ( $strh ) );
} else {
$strh = NULL;
}
return $strh;
}
___
$account = $_POST['cuenta'];
$cuenta = seguridad1($cuenta);

query ("SELECT blababa WHERE account = '$cuenta'");

If you know another way to create more functions for more security please tell :P (I know you maybe create more secure functions and you dont want to revelate ((For avoid cheaters)) ).

PS: I dont know but the array for the query always its blank result!!.

Guaresnay
31.07.2007, 13:39
SQL injecction possible with that query... be carefull...
WHERE account = '".$_POST['account']."' AND

' OR 1=1; --
It was just to give a basic idea..

Yes I know but for now its for test. After I test I Put this L2cp modded function:

function seguridad1($strh) {
$banwordshh = array ("'", ",", ";", "--", "%", "-", "SELECT", "DROP", "UPDATE", "QUERY", "%", "IN", "UNION, "\"", "'");
if ( eregi ( "[a-zA-Z0-9]+", $strh ) ) {
$strh = str_replace ( $banwordshh, '', strtolower ( $strh ) );
} else {
$strh = NULL;
}
return $strh;
}
___
$account = $_POST['cuenta'];
$cuenta = seguridad1($cuenta);

query ("SELECT blababa WHERE account = '$cuenta'");

If you know another way to create more functions for more security please tell :P (I know you maybe create more secure functions and you dont want to revelate ((For avoid cheaters)) ).

PS: I dont know but the array for the query always its blank result!!.
In your example you are changing every posted account and in most cases it will look for an unexisting account.
Try using something like this:

$account = trim($_POST['account']);
if ((!eregi("^[[:alnum:]]{2,14}$", $account)) || (eregi("[[:space:]]{1,}", $account))){
$error = "Invalid Account";
}
if(!$error){
mssql_query("lalala");
}else{
print $error;
}

Then you can add some java script to ur code to add some more security.