Giter Site home page Giter Site logo

taylornetwork / laravel-username-generator Goto Github PK

View Code? Open in Web Editor NEW
49.0 4.0 9.0 321 KB

Automatically generate usernames for Laravel User Model

Home Page: https://docs.taylornetwork.io/laravel-username-generator

License: MIT License

PHP 100.00%
username username-generator generator laravel laravel-package package php php8 php80 laravel9

laravel-username-generator's People

Contributors

john-climer avatar nikolaynikolaevn avatar samueljtaylor avatar stylecibot avatar timothyasp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-username-generator's Issues

Bug impossible to get a username

First of all, thank you for the very fast addition of the feature, it's the first time I've seen such a reactivity!
Unfortunately I have a problem, I installed the package, published the configuration (php artisan vendor:publish), and tried to use the package with tinker (php artisan tinker) but it doesn't seem to work:
Capture d’écran 2019-10-31 à 20 17 15

Capture d’écran 2019-10-31 à 20 18 23

Can you help me ?

Assignment error

Hey Samuel

I get a duplicate key error when I try to add a unique index to my username column, and there are indeed duplicate values.

I reckon there is an assignment error in Generator.php right here: https://github.com/taylornetwork/laravel-username-generator/blob/master/src/Generator.php#L132

You assign the outcome of the comparison instead of the actual count, adding brackets would solve this:

if(($similar = count($this->model->findSimilarUsernames($this->username))) > 0) {

I'd write a PR but it's such a small fix, could you do this? Thank you for this package and thanks in advance.

Warm regards

Pieter

Class '\App\User' not found

I can't update the configuration using this line:

public function generatorConfig(&$generator)
{
    $generator->setConfig(['model' => '\App\Models\User']);
}

How do I use this package if my User model doesn't have name column ?

I get an error when I try to add the Trait to the User Model with

use FindSimilarUsernames, GeneratesUsernames;

Return value of App\Models\User::getField() must be of the type string, null returned {"exception":"[object] (TypeError(code: 0): Return value of App\\Models\\User::getField() must be of the type string, null returned at /Users/vikram/Sites/.../vendor/taylornetwork/laravel-username-generator/src/GeneratesUsernames.php:52)
[stacktrace]

Not working with cyrillic strings

Hi!

I noticed that the generator returns an empty string if the input data is in cyrillic.

Could you please fix it? Thanks in advance!

Suggestion: Add a PascalCase setting for generated usernames.

I've looked around the documentation and tried a few things but couldn't seem to find a way to force generated usernames to use PascalCase.

For example, I was given the randomly generated username of Happybiographer, but I would love this to instead be HappyBiographer.

I appreciate that when it comes to converting usernames, you wouldn't really be able to convert to PascalCase successfully so perhaps it should just behave the same as 'mixed' when converting. But certainly when generating a random adjective-noun username it would be great to be able have this feature.

Is this possible?

Not respecting nouns/adjectives in config

I tried adding a small list of words (nouns and adjectives) in the dictionary config but I am still getting usernames with words not in the list.
In /config/username_generator.php:

    /*
     * Add your own adjective and nouns word lists here if don't want to use the default
     */
    'dictionary' => [
        'adjectives' => ['sly','smart','sneaky'],
        'nouns'      => ['fox','rabbit','mouse'],
    ],

And generating a username with this method:

$username = UsernameGenerator::generate();

I also tried clearing config cache in laravel but still getting results like "invitingbuccane".

Unique possibly fails

Possible bug where "unique" values end up not being unique if too short and we do the random pad.

This will only happen if:

  • Too short action is to pad with random digits
  • There is an after unique hook that causes the make unique to not catch the duplicate entry since it won't check ahead

Solution:

  • Run make unique again after everything
    OR
  • Only run it again if the username was too short
    OR
  • Restrict after make unique hook (don't really want to do that)

Ability to create username using a word dictionary

Hello,

First of all, thank you for this package which looks very interesting, however, in my case I can't use it, I don't have any useful information about my users (name, email...), they are all anonymous, I was wondering if it was possible to reproduce what the alenoir/username-generator library made in nodeJS does and generate a username from a list of nouns (nouns.json) and adjectives (adjectives.json).

That would be very practical.

Sugestion

This repo should be able to generate based on email address or any assigned emulator if available.

Possible SQL-Injection?

While reading your code i stumbled accross the following line (FindSimilarUsernames.php#L77):

return static::whereRaw("$column REGEXP '{$username}([0-9]*)?$'")->get();

Is the whereRaw necessary? Although you are stripping unwanted characters, this might lead to SQL-Injections, no? If a developer using your package does not know about this specific implementation and overwrites the allowed_characters Config-option and adds 'danagerous' characters, a user could inject SQL into the query by specifying a username.
I actually dont know much about REGEXP, but i am think that there has to be a way to use prepared statements here.

I found the following on laracasts:

$fulfills = Dialog::where('external_id', 'regexp', 'T[0-9]+')->get();

Which leads me to suggest something like this:

private function searchUsingRegexp(string $username)
{
    return static::where($this->getColumn(), 'REGEXP', $username."([0-9]*)?$")->get();
}

I'm actually not 100% sure if this fixes the SQL-Injection problem and still provide the same functunality.

Login with username

After the installation the package it is expected to be able to login with the username.

How to force the length of user name

I have tried the package as below:

 UsernameGenerator::generate($request->name . ' ' . $request->lastname)

.. and I passed the name 12s with something as the lastname but I got just s as the username.

I want to force the length of the user that it should generate about 5 chars. How should I do this?

Max length username

Hello
In the configuration I can see a variable to determine the minimum length for the username.
But is there any way to limit the maximum length?
Thank you,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.