发新话题
打印

用户注册验证安全问题

用户注册验证安全问题

代码如下:
复制内容到剪贴板
代码:
<?php
        header("Content-Type: text/html; charset=utf-8");//编码
        class Login{
                private $name;//用户名
                private $pwd;//未加密的密码
                private $md5Pwd;//加密后的密码
                private $pwd2;//第二次输入的密码
                private $email;//电子邮箱
                private $tishi;//问题
                private $md5Huida;//加密后的答案
                private $bir;//生日
                private $gender;//性别
                private $knowFrom;//从那里来的
               
                public  function __construct(){
                        $this->name = $_POST["name"];
                        $this->pwd = $_POST["pwd"];
                        $this->md5Pwd = md5($this->pwd);
                        $this->pwd2 = $_POST["pwd2"];
                        $this->email = $_POST["email"];
                        $this->tishi = $_POST["tishi"];
                        $this->md5Huida = md5($_POST["huida"]);
                        $this->bir = $_POST["byear"]."-".$_POST["bmonth"]."-".$_POST["bday"];
                        $this->gender = $_POST["gender"];
                        $this->knowFrom = $_POST["knowfrom"];
                }
               
                public function nulls(){
                        if ($this->name == ""){
                                echo "<script>alert('用户名不能为空!');window.history.go(-1);</script>";
                                exit;
                        }
                        if ($this->pwd == "" or strlen($this->pwd) < 6){
                                echo "<script>alert('密码不能为空,而且要大于6位的数字或字母!');window.history.go(-1);</script>";
                                exit;
                        }
                        if ($this->pwd != $this->pwd2){
                                echo "<script>alert('密码与重复密码不同!');window.history.go(-1);</script>";
                                exit;
                        }
                        if ($this->email == "" or !eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$this->email)){
                                echo "<script>alert('E-mail不能为空,或无效的E-mail地址!');window.history.go(-1);</script>";
                                exit;
                        }
                }
               
                public function inDbh(){
                        include("config/con#figda.php");
                        $sql=mysql_query("select * from user where name='$this->name'");
                        $info=mysql_fetch_array($sql);
                        if($info==true)
                         {
                                echo "<script>alert('该昵称已经存在!');history.back();</script>";
                            exit;
                         }
                         else
                         {  
                                $str="insert into user(name,pwd,email,tishi,huida,bir,gender,knowfrom)";
                                $str=$str."values('$this->name','$this->md5Pwd','$this->email','$this->tishi','$this->md5Huida','$this->bir','$this->gender','$this->knowFrom')";
                                mysql_query($str);
                            echo "<script>alert('恭喜您,注册成功!');window.location='../index.php';</script>";
                         }
                }
        }
        
        $inDbh = new Login();
        $inDbh->nulls();
        $inDbh->inDbh();
?>
为了安全起见用户输入的数据需要转义吗?如:
复制内容到剪贴板
代码:
$this->tishi =  htmlentities ($_POST["tishi"]);//用户输入的问题

TOP

发新话题