Comment se connecter par e-mail uniquement sans nom d'utilisateur?
-
-
Essayez-vous de supprimer complètement lesnoms d'utilisateur?Pourquoi leplugin Email Loginne fonctionne-t-ilpaspour vous?Are you trying to do away with usernames entirely? Why won't the Email Login plugin work for you?
- 0
- 2012-05-09
- Ryan
-
Je suis vraiment curieux de savoirpourquoi vous voudriez supprimer lesnoms d'utilisateur,carils sont à labase detoutes lesinformations utilisateur dans WordPress.C'est unpeu commeessayer de se débarrasser despostes -beaucoup detravailpourpeu debénéficeset unegarantie deproblèmes à l'avenir.I'm really curious why you'd want to do away with usernames, since those are the basis of all user information in WordPress. It's a bit like trying to do away with Posts - a lot of work for not a lot of payoff, and a guarantee of issues down the road.
- 0
- 2012-05-09
- SickHippie
-
@ Ryan- Jene pensepas queje serai capable deme débarrasser desnoms d'utilisateur,alorsje forcejuste lenom d'utilisateur à égaler l'adressee-mail.@Ryan- I don't think I'll be able to get rid of usernames so instead I'm just forcing the username to equal the email address.
- 1
- 2012-05-10
- agentsmith666
-
@SickHippie -pour la connexion,je pense que le courrier électroniqueestmeilleuret plus unique qu'unnom d'utilisateur.Jepréfère utiliser lenom d'utilisateur comme surnom lorsque l'utilisateurpublie.Vous avez raison,ce seraitpénible de se «débarrasser» de la variable «nom d'utilisateur»,c'estpourquoije ne le suispas.Je choisis simplement lenom d'utilisateur de l'utilisateur lors de soninscription (lenom d'utilisateur sera son adressee-mail; son surnom sera ce qu'il aentré commenom d'utilisateur).Enfin de compte,aucune variablen'estperdue,toutestintact.@SickHippie - for login I think email is better and more unique than a username. I'd rather use the username as the nickname when the user posts. You're right it would be a pain to get "rid" of the variable "username" which is why I am not. I'm just choosing the username for the user when they register (username will be their email address; their nickname will be what they entered as their username). In the end no variables are lost everything is intact.
- 0
- 2012-05-10
- agentsmith666
-
Mais si lesnoms d'utilisateurne peuventpas êtremodifiés (comportementpar défaut de WordPress),que sepasse-t-il lorsqu'un utilisateur change d'adressee-mail?Si un utilisateur,parexemple,quitte Hotmailet accède à Gmail,est-ilbloqué à l'aide de son adresse Hotmailpour se connecter à votre site?Sinon,ilspeuvent changer leur adressee-mailet continuer à utiliser leur ancienne adressee-mailpour se connecter (nom d'utilisateur),vous laissant dans lamêmeposition.Celan'apas de sens de restreindre artificiellement les options de connexion d'un utilisateurjustepour créerplus detravailpour vous-mêmepour une solution quine résout aucunproblème.Deplus,lesnoms d'utilisateur sont uniques,pointfinal.WordPressgère cela.But if usernames can't be changed (default WordPress behavior), what happens when a user changes their email address? If a user, for example, leaves Hotmail and goes to Gmail, are they stuck using their Hotmail address to log into your site? If not, then they can change their email address, and still use their old email address to login (username), leaving you in the same position. It doesn't make sense to artificially restrict a user's login options just to create more work for yourself for a solution that solves no problems. Also, usernames are unique, period. WordPress handles that.
- 0
- 2012-05-10
- SickHippie
-
@SickHippie - Vous avez raisonpuisque la valeurpar défaut de Wordpressest dene pas autoriser l'utilisateur à changer sonnom d'utilisateur,sonnom d'utilisateur/adressee-mail resterait lemêmemême s'il changeait son adressee-mail de contact.J'ai considéré que depuis le débutet d'aprèsmapropreexpérience,j'ai constaté que lesgens «suppriment» rarement une adressee-mail.Ilspeuventen obtenir denouveaux,maisgénéralementils auronttoujours les anciens.Et si cen'estpeut-être dans ces rares circonstances,nous le changeronsmanuellement dans labase de données.J'apprécie vraiment vos commentaireset votreperspicacité SickHippie!Maintenant,j'espère une solution àmonmessage :)@SickHippie - You're right since Wordpress's default is not to allow user's to change their username their username/email address would remain the same even if they were to change their contact email address. I've considered that from the beginning and in my own experience I have found that people rarely "delete" an email address. They may get new ones but typically they'll still have their old ones. And if not perhaps in those rare circumstances we'll manually change it in the database. I do really appreciate your feedback & insight SickHippie! Now I hope for a solution to my post :)
- 1
- 2012-05-13
- agentsmith666
-
6 réponses
- votes
-
- 2014-06-12
Mise àjour: J'ai créé unpluginpour la connexion,l'enregistrementet la récupération dumot depassepare-mail. https://wordpress.org/plugins/smart-wp-login/
Réponseen bref,vouspouvez configurer WordPresspour vous connecterpare-mail.
Trois étapes:
- Supprimer lafonction d'authentificationpar défaut
- Ajouter unefonction d'authentificationpersonnalisée
- Remplacez letexte "Nom d'utilisateur" dans wp-login.phppar "E-mail"
Une remarque:
- Nemodifiezpas lesfichiersprincipaux.
Supprimez lafonction d'authentificationpar défaut de WordPress.
WordPress utilise lefiltre " authentifier "poureffectuer une validation supplémentaire lors de la connexion de l'utilisateur.
remove_filter('authenticate', 'wp_authenticate_username_password', 20);
Ajouter unefonction d'authentificationpersonnalisée
add_filter('authenticate', function($user, $email, $password){ //Check for empty fields if(empty($email) || empty ($password)){ //create new error object and add errors to it. $error = new WP_Error(); if(empty($email)){ //No email $error->add('empty_username', __('<strong>ERROR</strong>: Email field is empty.')); } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email $error->add('invalid_username', __('<strong>ERROR</strong>: Email is invalid.')); } if(empty($password)){ //No password $error->add('empty_password', __('<strong>ERROR</strong>: Password field is empty.')); } return $error; } //Check if user exists in WordPress database $user = get_user_by('email', $email); //bad email if(!$user){ $error = new WP_Error(); $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.')); return $error; } else{ //check password if(!wp_check_password($password, $user->user_pass, $user->ID)){ //bad password $error = new WP_Error(); $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.')); return $error; }else{ return $user; //passed } } }, 20, 3);
Remplacez letexte "Nom d'utilisateur" dans wp-login.phppar "E-mail"
Nouspouvons utiliser lefiltre gettext pour remplacer letexte "Nom d'utilisateur"par "E-mail" sansmodifier lesfichiersprincipaux.
add_filter('gettext', function($text){ if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){ if('Username' == $text){ return 'Email'; } } return $text; }, 20);
J'ai également écrit un article détaillé surmonblog http://www.thebinary.in/blog/wordpress-login-using-email/
Update: I have created a plugin for login, registration and retrieve password with email. https://wordpress.org/plugins/smart-wp-login/
Answer in short, you can configure WordPress to login with email.
Three Steps:
- Remove default authentication function
- Add custom authentication function
- Change text "Username" in wp-login.php to "Email"
One Note:
- Don't edit core files.
Remove WordPress default authentication function.
WordPress uses "authenticate" filter to perform additional validation at user login.
remove_filter('authenticate', 'wp_authenticate_username_password', 20);
Add custom authentication function
add_filter('authenticate', function($user, $email, $password){ //Check for empty fields if(empty($email) || empty ($password)){ //create new error object and add errors to it. $error = new WP_Error(); if(empty($email)){ //No email $error->add('empty_username', __('<strong>ERROR</strong>: Email field is empty.')); } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email $error->add('invalid_username', __('<strong>ERROR</strong>: Email is invalid.')); } if(empty($password)){ //No password $error->add('empty_password', __('<strong>ERROR</strong>: Password field is empty.')); } return $error; } //Check if user exists in WordPress database $user = get_user_by('email', $email); //bad email if(!$user){ $error = new WP_Error(); $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.')); return $error; } else{ //check password if(!wp_check_password($password, $user->user_pass, $user->ID)){ //bad password $error = new WP_Error(); $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.')); return $error; }else{ return $user; //passed } } }, 20, 3);
Change text "Username" in wp-login.php to "Email"
We can use gettext filter to change text "Username" to "Email" without editing core files.
add_filter('gettext', function($text){ if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){ if('Username' == $text){ return 'Email'; } } return $text; }, 20);
I have also written a detailed article at my blog http://www.thebinary.in/blog/wordpress-login-using-email/
-
Belle réponse NishantNice answer Nishant
- 2
- 2014-06-12
- Andrew Bartel
-
utile!Dansmon cas,je supprime simplement les caractères spéciaux dese-mailset enfait unnom d'utilisateur.donc [email protected] devient user_example_comet cela afonctionné.useful! In my case I just strip email special characters and make it a username. so [email protected] becomes user_example_com and it worked.
- 0
- 2018-04-28
- wpcoder
-
- 2012-05-10
C'estpossible,vous devez changer lefiltre dunom.
// remove the default filter remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); // add custom filter add_filter( 'authenticate', 'fb_authenticate_username_password', 20, 3 ); function fb_authenticate_username_password( $user, $username, $password ) { // If an email address is entered in the username box, // then look up the matching username and authenticate as per normal, using that. if ( ! empty( $username ) ) $user = get_user_by( 'email', $username ); if ( isset( $user->user_login, $user ) ) $username = $user->user_login; // using the username found when looking up via email return wp_authenticate_username_password( NULL, $username, $password ); }
Une alternativeest unplugin,là voustrouvez via Google oder dans le repoplugin;peut-être ceplugin .
It's possible, you must change the filter for the name.
// remove the default filter remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); // add custom filter add_filter( 'authenticate', 'fb_authenticate_username_password', 20, 3 ); function fb_authenticate_username_password( $user, $username, $password ) { // If an email address is entered in the username box, // then look up the matching username and authenticate as per normal, using that. if ( ! empty( $username ) ) $user = get_user_by( 'email', $username ); if ( isset( $user->user_login, $user ) ) $username = $user->user_login; // using the username found when looking up via email return wp_authenticate_username_password( NULL, $username, $password ); }
An alternative is an plugin, there you find via Google oder in the plugin repo; maybe this plugin.
-
Mercipour la réponse,maisje ne saispas si vous avez lumonmessage ou sije n'aipas été assez clair.Jem'excusepour ce dernier.Dansmon article original,j'aimentionné leplugin WP_Email_Login;lepluginexact d'oùprovient votre codeet votre lien.Voicimonmessage d'origine: "Au début,j'étais ravi de voir WP_Email_Login uniquementpour découvrir que vouspouveztoujours utiliser votrenom d'utilisateurpour vous connecter."<--- Voir leproblème Jepeuxtoujours utiliser unnom d'utilisateur,c'estpourquoi cepluginne fonctionnerapas.Commeje nepeuxpasme débarrasser desnoms d'utilisateur,je pense remplacer lafonction d'enregistrementen forçant lenom d'utilisateur à égaler l'adressee-mail.Thanks for the reply however I'm not sure if you read my post or if I wasn't clear enough. I apologize for the latter. In my original post I mentioned WP_Email_Login plugin; the exact plugin your code and link is from. Here's my original post: "At first I was delighted to see WP_Email_Login only to find out you can still use your username to login." <--- See the problem I can still use a username so that's why this plugin will not work. Since I can't do away with usernames I'm thinking of overriding the register function by forcing the username to equal the email address.
- 0
- 2012-05-10
- agentsmith666
-
Cependant,je cherche unmoyen d'accomplir cela sansmodifier lesfichiersprincipaux.Si cen'estpaspossible,c'estbien maisj'aimerais savoir detoutefaçon.Merci!However I'm searching for a way to accomplish this without editing the core files. If it's not possible that's fine but I'd like to know either way. Thanks!
- 0
- 2012-05-10
- agentsmith666
-
c'est unmoyen sansmodifier lesfichiersprincipaux.Copiez le code dans unplugin,activezet prêt.this is a way without editing the core files. Copy the code in a plugin, activate and ready.
- 0
- 2013-04-01
- bueltge
-
- 2013-06-01
En utilisant le code ci-dessus:
// Change login credentials // remove the default filter remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); // add custom filter add_filter( 'authenticate', 'my_authenticate_username_password', 20, 3 ); function my_authenticate_username_password( $user, $username, $password ) { // If an email address is entered in the username box, // then look up the matching username and authenticate as per normal, using that. if ( ! empty( $username ) ) { //if the username doesn't contain a @ set username to blank string //causes authenticate to fail if(strpos($username, '@') == FALSE){ $username = ''; } $user = get_user_by( 'email', $username ); } if ( isset( $user->user_login, $user ) ) $username = $user->user_login; // using the username found when looking up via email return wp_authenticate_username_password( NULL, $username, $password ); }
Tout ce quenous avions àfaire était de vérifier que lenom d'utilisateurfourni ressemblait aumoins à une-mailet sinon de saboter lenom d'utilisateur.
Using the above code:
// Change login credentials // remove the default filter remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); // add custom filter add_filter( 'authenticate', 'my_authenticate_username_password', 20, 3 ); function my_authenticate_username_password( $user, $username, $password ) { // If an email address is entered in the username box, // then look up the matching username and authenticate as per normal, using that. if ( ! empty( $username ) ) { //if the username doesn't contain a @ set username to blank string //causes authenticate to fail if(strpos($username, '@') == FALSE){ $username = ''; } $user = get_user_by( 'email', $username ); } if ( isset( $user->user_login, $user ) ) $username = $user->user_login; // using the username found when looking up via email return wp_authenticate_username_password( NULL, $username, $password ); }
All we had to do was check that the provided username at-least looked like a email and if not sabotage the username.
-
Plutôt que la vérification de chaîneprimitivepour `` '@' 'dans lenom d'utilisateur,Wordpress a unefonctionintégréepratique: [sanitize_email] (http://codex.wordpress.org/Function_Reference/sanitize_email) renverra une adressee-mail valideformat ou rien: `sanitize_email ('email¬!" @business_com');//Ne renvoie rien`Rather than the primitive string check for `'@'` in the username, Wordpress has a handy built-in function: [sanitize_email](http://codex.wordpress.org/Function_Reference/sanitize_email) will return either a valid email address format or nothing: `sanitize_email('email¬!"@business_com'); // Returns nothing`
- 0
- 2014-07-07
- indextwo
-
- 2016-07-17
ilest déjà dans
WP-CORE
!maintenant wordpresspermet déjà d'enregistrer EMAIL commenom d'utilisateur.mais si vousparlez d'utilisateurs déjàenregistrés,essayez les réponses répertoriées.
it is already in
WP-CORE
!now wordpress already allows to register EMAIL as username. but if you are talking about already registered users, then try the listed answers.
-
- 2014-02-19
De légèresmodifications du code ci-dessus devraient suffirepour créer une solution élégante. La documentationpour le hook d'authentification indique qu'un objet
WP_User
ou l'objetWP_Error
doit être renvoyé.Le code source de lafonction wp_authenticate_username_password passepar quelques vérifications assez simples;nouspouvons simplement reproduire lafaçon dont ces vérifications sonteffectuéeset créer unnouvel objet
WP_Error
pourgérer l'adressee-mail. Alternativement,nouspourrionsmême capturer le codewp_authenticate_username_password
et lemodifier sinous le voulions,bien que cela sembleinutile àmoins que vousne souhaitiez vraimentpersonnaliser lefonctionnement des choses. Le code ci-dessous devraitfaire l'affaire: (bien queje ne l'aipastestémoi-même ...)// Remove the default authentication function remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); // Add the custom authentication function add_filter( 'authenticate', 'custom_authenticate_username_password', 20, 3 ); function custom_authenticate_username_password( $user, $username, $password ) { // Get the WP_User object based on the email address if ( ! empty( $username ) ) { $user = get_user_by( 'email', $username ); } // Return a customized WP_Error object if a WP_User object was not be returned (i.e. The email doesn't exist or a regular username was provided) if ( ! $user ) { return new WP_Error( 'invalid_username_email', sprintf( __( '<strong>ERROR</strong>: Invalid username. Please log in with your email address. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() ) ); } // Hand authentication back over to the default handler now that we a have a valid WP_User object based on the email address return wp_authenticate_username_password( null, $username, $password ); }
Slight modifications to the code above should be all that is needed to create an elegant solution. The documentation for the authenticate hook states that either a
WP_User
object orWP_Error
object should be returned.The source code for the wp_authenticate_username_password function runs through some pretty simple checks; we can just replicate the way those checks are done, and create a new
WP_Error
object to deal with the email address. Alternatively, we could even jack thewp_authenticate_username_password
code and modify it if we wanted, although that seems unnecessary unless you really want to customize how things function. The code below should do the trick: (Although I haven't tested it myself...)// Remove the default authentication function remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); // Add the custom authentication function add_filter( 'authenticate', 'custom_authenticate_username_password', 20, 3 ); function custom_authenticate_username_password( $user, $username, $password ) { // Get the WP_User object based on the email address if ( ! empty( $username ) ) { $user = get_user_by( 'email', $username ); } // Return a customized WP_Error object if a WP_User object was not be returned (i.e. The email doesn't exist or a regular username was provided) if ( ! $user ) { return new WP_Error( 'invalid_username_email', sprintf( __( '<strong>ERROR</strong>: Invalid username. Please log in with your email address. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() ) ); } // Hand authentication back over to the default handler now that we a have a valid WP_User object based on the email address return wp_authenticate_username_password( null, $username, $password ); }
-
- 2018-04-17
Ilexiste unpluginpour cela:
Forcer la connexionpare-mail
https://br.wordpress.org/plugins/force-email-connexion/
C'est aussi sur Github: https://github.com/miya0001/force-email-login
There's a plugin for that:
Force Email Login
https://br.wordpress.org/plugins/force-email-login/
It's also on Github: https://github.com/miya0001/force-email-login
-
Agréable.Vouspouvez simplementplop https://raw.githubusercontent.com/miya0001/force-email-login/master/force-email-login.php dansmu-pluginsNice. You can just plop https://raw.githubusercontent.com/miya0001/force-email-login/master/force-email-login.php into mu-plugins
- 0
- 2020-02-14
- squarecandy
Après avoir cherchépendant quelquesjourset lu desfils de 2 ans,j'ai dumal àtrouver une solution auproblème de connexion des utilisateurspare-mail uniquement.
Au début,j'étais ravi de voir WP_Email_Loginpour découvrir que vouspouveztoujours utiliser votrenom d'utilisateurpour vous connecter. Jene saispas comment écrire celaen tant queplugin. Monidéeest de remplacer lafonction register_new_user. Jen'aipas vu cela sur la liste desfonctions "enfichables". Puis-je utiliser desfiltres/une actionpour yparvenir?
Jeme rends compte que cen'estpas à lamode d'éditer lesfichiers debase,j'espère donc qu'une solutionexiste,mais s'iln'enexistepas,je vaistenterma chance. Dans lapremière ligne de lafonction "register_new_user" dans wp-login.phpje peux ajouter:
Celafonctionnetrèsbien car WordPressne permetpas auxgens de changer leurnom d'utilisateur. Dans l'écran d'enregistrement (formulaire),il demande lenom d'utilisateur & amp; Email; Je voudrais définir lenom d'utilisateur sur la variable Nickname (si quelqu'unpeutme dire comment la variable surnomest appelée ou oùelleest définie lors de l'enregistrement,cela serait apprécié).
Salutations,
Smith