php - make checks with class and stop the script -
i created script change user's password, when checking continues.
class mudar_senha{ protected $page_return = 'mudar_senha'; private function encriptasenha($senha) { return base64_encode(pack("h*", sha1(utf8_encode($senha)))); } private function query_senha(){ global $_lang; $user_id = $_post['id_user']; $q=new query; $q ->select() ->from('`usuarios`') ->where_equal_to( array( 'id'=>$user_id ) ) ->limit(1) ->run(); if($q){ $user=$q->get_selected(); return $user['senha']; } else{ return alerta($_lang[165]); retornar(null,$this->page_return); die; } } private function verify_senha($senha){ global $_lang; if($this->encriptasenha($senha) == $this->query_senha()){ return true; }else{ return alerta($_lang[203]); retornar(null,$this->page_return); die; } } private function verify_senhas(){ global $_lang; if($_post['cpass1'] == $_post['pass1']){ return true; }else{ return alerta($_lang[171]); retornar(null,$this->page_return); die; } } private function verify_length($senha){ global $_lang; switch($senha){ case(strlen($senha) < 6) : return $_lang[206]; die; case(strlen($senha) > 11): return alerta($_lang[205]); retornar(null,$this->page_return); die; default: return true; } } private function verify_caracteres($senha){ global $_lang; if(preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $senha)){ return alerta($_lang[204]); retornar(null,$this->page_return); exit; }else{ return true; } } final public function _build(){ global $_lang; if($this->verify_senha($_post['req1']) == true); if($this->verify_senhas() == true); if($this->verify_length($_post['pass1']) == true); if($this->verify_caracteres($_post['pass1'])== true); $q=new query; $q ->update('usuarios') ->set( array( 'senha' => $this->encriptasenha($_post['pass1']), 'pass_decode' => $_post['pass1'], ) ) ->where_equal_to( array( 'id'=>$_post['id_user'] ) ) ->limit(1) ->run(); if($q){ alerta($_lang[207]); retornar(null,$this->page_return); }else{ alerta($_lang[165]); retornar(null,$this->page_return); exit; } } } $q = new mudar_senha; $q->_build();
there 3 checks - correct password? - correct passwords? - password length - special characters
if denies checks script returns true, , _build function checks if changes continue normally.
all of die;
statements after return
statements. if you're going kill script, remove return
statement beforehand since value won't matter anyway.
Comments
Post a Comment