如果你可以解密,别人也同样可以。这样就没有什么密码的意义了。
有加密就可以了。使用的时候将提交的密码加密后在去找匹配的记录。
<?
$username="user";
$userpasswd="passwd";
$sql="select count(*) from tablename where username=".$username." and userpasswd=".md5($userpasswd);
?>
md5就是现在应用的比较广泛的加密函数之一。

解决方案 »

  1.   

    to uGain(向★★★★★努力ing) 主要是别人不知道我用什么算法加的密啊这样他就不能解了
      

  2.   

    to uGain(向★★★★★努力ing) 另外<?
    $username="user";
    $userpasswd="passwd";
    $sql="select count(*) from tablename where username=".$username." and userpasswd=".md5($userpasswd);
    ?>
    上面的不安全$username=   " or '1'='1'
      

  3.   

    to uGain(向★★★★★努力ing) 
    Sql语句密码验证安全漏洞 
    作者: 潘雷  评价:  上站日期: 2002-01-14  
    内容说明:  
    来源:  --------------------------------------------------------------------------------
      Sql语句作为国际标准的数据库查询语句,在各种编程环境中得到了广泛的应用。作为一个成熟、稳定的系统,用户登陆和密码验证是必不可少的。笔者在平时的编程工作中发现,许多程序员在用sql语句进行用户密码验证时是通过一个类似这样的语句来实现的:  Sql="Select * from 用户表 where 姓名='"+name+"' and 密码='"+password+"'"  其中name和password是存放用户输入的用户名和口令,通过执行上述语句来验证用户和密码是否合法有效。但是通过分析可以发现,上述语句却存在着致命的漏洞。当我们在用户名称中输入下面的字符串时:111'or'1=1,然后口令随便输入,我们设为aaaa。变量代换后,sql语句就变成了下面的字符串:  Sql="Select * from 用户表 where 姓名='111'or'1=1' and 密码='aaaa'  我们都知道select语句在判断查询条件时,遇到或(or)操作就会忽略下面的与(and)操作,而在上面的语句中1=1的值永远为true,这意味着无论在密码中输入什么值,均能通过上述的密码验证!这个问题的解决很简单,方法也很多,最常用的是在执行验证之前,对用户输入的用户和密码进行合法性判断,不允许输入单引号、等号等特殊字符。  上述问题虽然看起来简单,但确实是存在的。例如在互联网上很有名气的网络游戏"笑傲江湖"的早期版本就存在着这样的问题,笔者也是在看了有关此游戏的漏洞报告后才仔细分析了自己以前编写的一些程序,竟然有不少也存在着这样的漏洞。这确实应该引起我们的注意。这也暴露出包括笔者在内的年轻程序员在编程经验和安全意识上的不足。同时也提醒我们编程工作者在程序设计时应当充分考虑程序的安全性,不可有半点马虎,一个看似很小的疏漏可能就会造成很严重的后果。 
     
      

  4.   

    <?
    //加密
    functionecrypt_date($data,$password)
    {
    for($i=0,$j=0;$i<strlen($data);$i++,$j++)
    {
    $middle=ord(substr($data,$i,1))+
    ord(substr($password,$j,1));
    if($j>strlen($password))
    {
    $j=0;
    }
    $estr.=chr($middle);
    }
    return($estr);
    }
    //解密
    function decrypt_data($data,$password)
    {
    for($i=0,$j=0;$i<strlen($data);$i++,$j++_
    {
    $middle=ord(substr($data,$i,1))-
    ord(substr($data,$j,1));
    if($j>strlen($password))
    {
    $j=0;
    }
    $estr.-chr($middle);
    }
    return($estr);
    }
    ?>
      

  5.   

    所有用户的输入都应该做处理。
    一些最应该做的处理:
    $val = preg_replace( "/&/"         , "&amp;"         , $val );
         $val = preg_replace( "/<!--/"      , "&#60;&#33;--"  , $val );
         $val = preg_replace( "/-->/"       , "--&#62;"       , $val );
         $val = preg_replace( "/<script/i"  , "&#60;script"   , $val );
         $val = preg_replace( "/>/"         , "&gt;"          , $val );
         $val = preg_replace( "/</"         , "&lt;"          , $val );
         $val = preg_replace( "/\"/"        , "&quot;"        , $val );
         $val = preg_replace( "/\|/"        , "&#124;"        , $val );
         $val = preg_replace( "/\n/"        , "<br>"          , $val ); // Convert literal newlines
         $val = preg_replace( "/\\\$/"      , "&#036;"        , $val );
         $val = preg_replace( "/\r/"        , ""              , $val ); // Remove literal carriage returns
         $val = preg_replace( "/!/"         , "&#33;"         , $val );
         $val = preg_replace( "/'/"         , "&#39;"         , $val ); // IMPORTANT: It helps to increase sql query safety.
         $val = stripslashes($val);                                     // Swop PHP added backslashes
         $val = preg_replace( "/\\\/"       , "&#092;"        , $val ); // Swop user inputted backslashes