i5hi / slider_captcha_server

a slider captcha puzzle creation and verification library to protect http apis
GNU General Public License v3.0
2 stars 4 forks source link

Add verification function to lib.rs #1

Closed i5hi closed 1 year ago

i5hi commented 1 year ago

Currently verification is left to the user; as illustrated in the POST puzzle/solution route in examples/actix.rs

This should instead be implemented and provided as part of the library.

It can have a signature as follows:

verify_puzzle(solution: f64, submission: f64, error_margin: f64)->bool;
i5hi commented 1 year ago

the library is defined in src/lib.rs, here you can see all the structs and functions exposed by the library.

The examples folders are examples of how you can use the library - notice the first few lines of import statements. We only import generate_puzzle and SlidePuzzle.

All verification is - is checking if the provided solution is within a margin of error of the actual solution - logic for which is contained in the POST puzzle/solution route.

Copy this logic into lib.rs as a verify function and import it into the example.

To know if you got it right, run the example and manually test via curl.

Note: The example has nothing to do with the library itself, it is just an example of how to use the library.

Ignore how the example server stores the solution as an 'Arc<Mutex<HashSet>>>' 
this is up to the user of the library. 
Users can store the request id and solution in memory as the example or in redis or in postgres or whatever, 
what the library is concerned with is just verification of the provided solution against the actual solution within a margin of error.
i5hi commented 1 year ago

Thanks @yashwanthambati