clarkeash/doorman

better code creation

Closed this issue · 10 comments

Right now the code generator just uses Str::random(5) so there is a big chance of duplication

A lot of threads around the web about randomness also this one for laravel laravel/ideas#161

I think a good compromise would be to extract the code generator process into its own class, and give the user an option to override code generator, so if someone is looking for some more secure way can easily use something like uniqueid or some uuid library and add some more options like checking for existence (there is no simple way of generating random string in multiple machines and to make sure there is no duplication without checking the db first)

Maybe that could be temporally fixed by checking if a model already exists.

I am happy to add this, I am away at the moment but will get to it soon.

I'd suggest a config type (string, uuid, etc) and a code length.

@necrogami Added an option to customize the code length in #19

I'd be interested in helping with this. I'm keen to have a variable-length (or, at least, longer) invite code, but also (perhaps, and this is personal preference) codes generated along the lines of:

  • LLL-LLL (where L is a letter)
  • LLLL-LLLL
  • LLLN-LLLN (where L is a letter and N is a number)
  • LLNN-LLNN
  • LLLNNN
  • lowercasewordNNN (where N is a number)
  • lowercaseword-lowercaseword

I know these won't be to everyone's tastes but with the 'driver' system you mentioned, they could be potential choices.

I have a uuid implementation, have a few other things to do on doorman, but hoping to get this to you soon

@clarkeash Ping me if you need help!

looking forward to an update!

Hey Guys,

I have been holding off on this as I wanted to get a few other features into doorman, but that doesnt look like I am gonna be able to get those in just yet.

There is a UUID implementation committed, just go into config/doorman.php and set the driver to 'uuid', and thats it everything should work as normal.

I have not tagged a release yet, so it would be great if a few of you could pull in dev-master and give this a try before I tag 2.0.0

Sorry this has taken so long.

Hey, this is fixed. Sorry it took so long I havent had much time to work on open source lately.
I should be tagging 2.0 later today with this fix in (will require laravel 5.6 and php 7.1)