# How to compare request data with db?

**URL:** <https://discourse.getcockpit.com/t/how-to-compare-request-data-with-db/1971>\
**Category:** Support\
**Created:** [June 22, 2021, 5:13pm UTC](https://discourse.getcockpit.com/t/how-to-compare-request-data-with-db/1971 "2021-06-22T17:13:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drascom](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/drascom/32/718_2.png) [@drascom](https://discourse.getcockpit.com/u/drascom)\
**Post date:** [June 22, 2021, 5:13pm UTC](https://discourse.getcockpit.com/t/how-to-compare-request-data-with-db/1971/1 "2021-06-22T17:13:46Z")

</div>

hi there, i’m trying to implement separated login system to use at API and im using a collection to keep members data for splitting backend users and frontend users.  
i need to compare email and password at backend and i tried to use collections.find.before and collections.find.after hooks for it.  
i know those can be nested but i don’t know how to get incoming data to compare with db and send response as true or false.

```auto
 $app->on('collections.find.before.members', function($name, $options) {
       //need to get posted data here 
    $this->on('collections.find.after.members', function($name, &$entry){
        //need to compare with existing data
        //than alter the response as true or false
        }, -9999);
 }, 9999); 

```

Thanks in advance for any help

---

<div class="post-metadata">

**Author:** ![drascom](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/drascom/32/718_2.png) [@drascom](https://discourse.getcockpit.com/u/drascom)\
**Post date:** [June 23, 2021, 10:28am UTC](https://discourse.getcockpit.com/t/how-to-compare-request-data-with-db/1971/2 "2021-06-23T10:28:43Z")

</div>

i have solved the problem.i think it is a simple backend validation  
now i need to learn to call this with custom endpoint…🙂 😄  
the code is below for who may need in future

```auto
//run only for api request
if (COCKPIT_API_REQUEST && $app->param('populate', false)) {
         //run only for certain collection "members" here 
        $app->on('collections.find.after.members', function($name, &$entry) {
          //if matched record found
         if(count($entry) > 0 ){
            //get posted request field
            $requestedField = $this->request->request["filter"]["code"];
             
            //get db response data and extract necessary field
            $responseField = $entry[0]["code"];
             
            //clean default response body
             $entry=[];
            
            //set new field named "isconfirmed" and return comparsation result
            $entry["isconfirmed"]= ($firstField !== $responseField) ? true :false;
          }else{
                $entry["isconfirmed"]=false;
                $entry["text"]="no record found";
            }
        });
}

```
