We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Controller is resetting the connection instead of getting variable

Hello friends, I am trying to use controller for user signup and for testing and developing purpos, I am using get method so I can see json encoded reposne in my webpage. Now the problem is that my controller is getting only one get variable which is "key" and I want it to verify with csrf session. After then when I try to catch all other details and set them to local variable, it is not loading the page and showing me error connection was reset on my browser.

public function signupAction()
{
    $this->view->disable();

    //Create a request instance
    $request = new Phalcon\Http\Request();
    if($request->getQuery("key") == $this->session->get("CSRF")){

        $key   = $request->getQuery("key");
        $email = ($request->getQuery("email")) ? $request->getQuery("email") : '';
        $uname = ($request->getQuery("uname")) ? $request->getQuery("uname") : '';
        $pass  = ($request->getQuery("pass")) ? $this->security->hash($request->getQuery("pass")) : '';

        if(!empty($key) && !empty($email) && !empty($uname) && !empty($pass)){
            $msg = array('hi'=>'hello');
        }else{
            $msg = array('error' => 'true', 'message' => 'Cachable error', 'details' => 'Please enter all details.');
        }

    }else{
        $msg = array('error' => 'true', 'message' => 'Token miss match');
    }

    $response = new \Phalcon\Http\Response();
    $response->setContent(json_encode($msg));
    echo($response->getContent());

}

These are current codes. If I try to access url localhost/signup?key=123 I am getting error on my page that all details are required. But if I try to access localhost/signup?key=123&uname=abc&[email protected]&pass=123456 my broser is showing me error of connection reset.

First I tried to catch variabled and save them in local vars as

$email   = $request->getQuery("email");

and it didn't work either. So can anyone tell me the reason why it is resetting the connection? It worked for once atleast.

Maybe this won't answer your question entirely, but please post the user input instead of sending it as query parameter. Think about the access logs and all the passwords floating there.

After changing that try in your controller:

$post = $this->request->getPost();
$key = $post['key'];
// etc.

I got the point where was the problem. It because of security has by $this->security->hash() that I user for encrypting password. I used it in my login controller too but it was resetting connection there too. And in my database I am using VARCHAR for password so it was not inserting password sometimes. I tried to change mysql with TEXT and it worked for few times. Later I tried to use my own encryption class and it worked perfect. So I need to see what is problem with security has.