# Sign in with email address?

**URL:** <https://forum.getkirby.com/t/sign-in-with-email-address/8355>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 26, 2017, 12:35pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355 "2017-08-26T12:35:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![starckio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/starckio/32/10405_2.png) [@starckio](https://forum.getkirby.com/u/starckio)\
**Post date:** [August 26, 2017, 12:35pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/1 "2017-08-26T12:35:42Z")

</div>

Hello,  
I would like to know if it is possible to connect with the email address?  
(This tutorial: [https://getkirby.com/docs/cookbook/authentication](https://getkirby.com/docs/cookbook/authentication))  
I try to replace “username” with “email” but it does not work.

Maybe I missed something?

Thank.

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [August 26, 2017, 3:45pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/2 "2017-08-26T15:45:17Z")

</div>

I wanted to check for myself because I also did this tutorial a while ago, and actually it seems that with the password, it does not work. Also it seems that the name or the first name alone does not work either.

Maybe a possible issue due to the core ?

`$user = $site->user(get('email')) and $user->login(get('password'))` =\> doesn’t work

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [August 26, 2017, 6:05pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/3 "2017-08-26T18:05:15Z")

</div>

You need to find the user by email address like this:

```auto
$user = $site->users()->findBy('email', get('email'));

```

Apart from that it’s the same. 🙂

---

<div class="post-metadata">

**Author:** ![starckio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/starckio/32/10405_2.png) [@starckio](https://forum.getkirby.com/u/starckio)\
**Post date:** [August 26, 2017, 9:57pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/4 "2017-08-26T21:57:39Z")

</div>

I had not thought of “findBy”…  
Thank you very much!

## Solution:

**controllers/login.php**

```
<?php 

return function($site, $pages, $page) {

  // don't show the login screen to already logged in users
  if($site->user()) go('/');

  // handle the form submission
  if(r::is('post') and get('login')) {

    // fetch the user by email and run the 
    // login method with the password
    if($user = $site->users()->findBy('email', get('email')) and $user->login(get('password'))) {
      // redirect to the homepage 
      // if the login was successful
      go('account');
    } else {
      // make sure the alert is being 
      // displayed in the template
      $error = true;
    }

  } else {
    // nothing has been submitted
    // nothing has gone wrong
    $error = false;  
  }

  return compact('error');

};

```

And,  
**template/login.php**

```
<?php snippet('header') ?>

<main class="main" role="main">

	<div class="text">
		<h1 class="title"><?php echo $page->subtitle()->or($page->title()) ?></h1>
		<?php echo $page->text()->kirbytext() ?>
	</diiv>
	
	<form method="post">
		<?php if($error): ?>
		<div class="alert error">
			<p><?php echo $page->alert()->html() ?></p>
		</div>
		<?php endif ?>

		<div class="field">
			<label for="email">Email</label>
			<input type="text" id="email" name="email">
		</div>
		<div class="field">
			<label for="password">Password </label>
			<input type="password" id="password" name="password">
		</div>
		<div class="field">
			<input class="btn" type="submit" name="login" value="Login">
		</div>
	</form>

</main>

<?php snippet('footer') ?>
```

---

<div class="post-metadata">

**Author:** ![ola](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ola/32/3465_2.png) [@ola](https://forum.getkirby.com/u/ola)\
**Post date:** [August 27, 2017, 7:00pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/5 "2017-08-27T19:00:50Z")

</div>

If I’m correct, this is for a custom built login page? Is it possible to change the regular panel login page to use email address instead of username?

People forget their passwords, but also their usernames… Email addresses is much better for login ID.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [August 27, 2017, 7:29pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/6 "2017-08-27T19:29:11Z")

</div>

> [@ola](#):
>
> Is it possible to change the regular panel login page to use email address instead of username?

Nope, not at the moment. But you can build a custom login page and then redirect the users to the Panel.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:32pm UTC](https://forum.getkirby.com/t/sign-in-with-email-address/8355/7 "2025-02-06T17:32:14Z")

</div>


