taylornetwork / laravel-username-generator Goto Github PK
View Code? Open in Web Editor NEWAutomatically generate usernames for Laravel User Model
Home Page: https://docs.taylornetwork.io/laravel-username-generator
License: MIT License
Automatically generate usernames for Laravel User Model
Home Page: https://docs.taylornetwork.io/laravel-username-generator
License: MIT License
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:
Can you help me ?
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
I can't update the configuration using this line:
public function generatorConfig(&$generator)
{
$generator->setConfig(['model' => '\App\Models\User']);
}
No working in laravel 5.6
It seems like all the configuration is taken from the config file but never over written
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]
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!
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?
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".
Possible bug where "unique" values end up not being unique if too short and we do the random pad.
This will only happen if:
Solution:
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.
my problem solved! :)
This repo should be able to generate based on email address or any assigned emulator if available.
Need to update config file path in service provider
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.
After the installation the package it is expected to be able to login with the username.
hi,
can i generate usernames for suggest?
please example code
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?
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,
According to the doc it generates a unique username but is there any way to get list of available usernames?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.