Generate code without guess |
Hello
I want to generate many code and save it in database and give it for shops So users get this code from shop and enter it in app. Now if user guest how do generate this codes so can enter many code in app How do i generate code that dont have static structure ?
If you need simple one off codes that dont need to have a specific value I would use a simple hash system.
For example creatinge the hash I would use todays data and exact time and hash that. For example MD5 would alway generate a 32 charatcer long code. This can be easily created in PHP and stored in the database. The app would then just check for this code. The app does not need to know the date time as it just checkst if it exist in the DB. The problem with this approch is the length of the code. If a user has to enter that manually then 32 char is rather long. I hope this helps and give syou some ideas.
On the package it said needs Windows 7 or better. So I installed Linux.
Here is something I use.
PHP Code: public function generate_code() { It was suggested to me here on these forums somewhere by Narf ages ago but I use it all the time on almost every site I do. It is great for generating unique codes for urls, for all sorts of records, rather than using id. I have it in a functions model that has all my useful functions in. You could use more random bytes if you wanted a longer code. Generates something like: 59aad953a91644ce Hope it helps, Paul PS This is not for security, this is just to generate a code I can use instead of an ID, i.e. Code: Not: www.mysite.co.uk/view/record/4
(09-29-2017, 10:43 AM)PaulD Wrote: Here is something I use. PHP Code: /** https://paragonie.com/blog/2015/07/commo...dom-string https://github.com/paragonie/random_compat @rtenny, using md5 width a timestamp is not the best idea. Use PaulD code or the random_str from paragonie.
(09-29-2017, 07:05 AM)rtenny Wrote: If you need simple one off codes that dont need to have a specific value I would use a simple hash system. Yes it is helpful Thanks
(09-29-2017, 10:43 AM)PaulD Wrote: Here is something I use. Yes it is good way |
Welcome Guest, Not a member yet? Register Sign In |