diff --git a/core/templates/login.php b/core/templates/login.php
index 641e0adb6e04f24ddfa3307773f8ebe87bc2dca6..6564847014b8abae3c04e9cfc83c9458fcd6194a 100644
--- a/core/templates/login.php
+++ b/core/templates/login.php
@@ -1,8 +1,8 @@
 <form action="index.php" method="post">
 	<fieldset>
-		<?php /*if($_['error']): ?>
+		<?php if($_['error']): ?>
 			<a href="index.php?lostpassword"><?php echo $l->t('Lost your password?'); ?></a>
-		<?php endif;*/ ?>
+		<?php endif; ?>
 		<?php if(empty($_['username'])): ?>
 			<input type="text" name="user" id="user" placeholder="<?php echo $l->t( 'Username' ); ?>" value="<?php echo !empty($_POST['user'])?$_POST['user'].'"':'" autofocus'; ?> autocomplete="off" required />
 			<input type="password" name="password" id="password" placeholder="<?php echo $l->t( 'Password' ); ?>" value="" required <?php echo !empty($_POST['user'])?'autofocus':''; ?> />
diff --git a/index.php b/index.php
index 68754fcc567a9ebdc464306061ba544918b6bc20..17429b9747646ee9f5e700c0866f1a4992423e91 100644
--- a/index.php
+++ b/index.php
@@ -63,7 +63,7 @@ elseif(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && is
 		OC_Util::redirectToDefaultPage();
 	}
 	else {
-		OC_Template::printGuestPage("", "login", array("error" => true, 'username' => isset($_COOKIE['oc_username'])?$_COOKIE['oc_username']:'' ));
+		OC_Util::displayLoginPage(array('error' => true));
 	}
 }
 
@@ -82,46 +82,14 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) {
 		}
 		OC_Util::redirectToDefaultPage();
 	} else {
-		OC_Template::printGuestPage('', 'login', array('error' => true, 'username' => isset($_COOKIE['oc_username'])?$_COOKIE['oc_username']:'' ));
-	}
-}
-
-// Someone lost their password:
-elseif(isset($_GET['lostpassword'])) {
-	OC_App::loadApps();
-	if (isset($_POST['user'])) {
-		if (OC_User::userExists($_POST['user'])) {
-			$token = sha1($_POST['user']+uniqId());
-			OC_Preferences::setValue($_POST['user'], "owncloud", "lostpassword", $token);
-			// TODO send email with link+token
-			OC_Template::printGuestPage("", "lostpassword", array("error" => false, "requested" => true));
-		} else {
-			OC_Template::printGuestPage("", "lostpassword", array("error" => true, "requested" => false));
-		}
-	} else {
-		OC_Template::printGuestPage("", "lostpassword", array("error" => false, "requested" => false));
-	}
-}
-
-// Someone wants to reset their password:
-elseif(isset($_GET['resetpassword']) && isset($_GET['token']) && isset($_GET['user']) && OC_Preferences::getValue($_GET['user'], "owncloud", "lostpassword") === $_GET['token']) {
-	OC_App::loadApps();
-	if (isset($_POST['password'])) {
-		if (OC_User::setPassword($_GET['user'], $_POST['password'])) {
-			OC_Preferences::deleteKey($_GET['user'], "owncloud", "lostpassword");
-			OC_Template::printGuestPage("", "resetpassword", array("success" => true));
-		} else {
-			OC_Template::printGuestPage("", "resetpassword", array("success" => false));
-		}
-	} else {
-		OC_Template::printGuestPage("", "resetpassword", array("success" => false));
+		OC_Util::displayLoginPage(array('error' => true));
 	}
 }
 
 // For all others cases, we display the guest page :
 else {
 	OC_App::loadApps();
-	OC_Template::printGuestPage('', 'login', array('error' => false, 'username' => isset($_COOKIE['oc_username'])?$_COOKIE['oc_username']:'' ));
+	OC_Util::displayLoginPage(array('error' => false));
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/lib/util.php b/lib/util.php
index 26d718da94471b0c7d6af6a5c95a04e72eceb665..f21ec8208b4703734e49a23083f1952bbaf919ae 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -258,6 +258,14 @@ class OC_Util {
 		return $errors;
 	}
 
+	public static function displayLoginPage($parameters = array()){
+		if(isset($_COOKIE["username"])){
+			$parameters["username"] = $_COOKIE["username"];
+		} else {
+			$parameters["username"] = '';
+		}
+		OC_Template::printGuestPage("", "login", $parameters);
+	}
 
 	/**
 	* Try to get the username the httpd server runs on, used in hints
diff --git a/lostpassword/index.php b/lostpassword/index.php
new file mode 100644
index 0000000000000000000000000000000000000000..6d629a71089b4302ff90352de8a612c1058661a0
--- /dev/null
+++ b/lostpassword/index.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+*/
+
+$RUNTIME_NOAPPS = TRUE; //no apps
+require_once('../lib/base.php');
+
+// Someone lost their password:
+if (isset($_POST['user'])) {
+	if (OC_User::userExists($_POST['user'])) {
+		$token = sha1($_POST['user']+uniqId());
+		OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token);
+		$email = OC_Preferences::getValue($_POST['user'], 'lostpassword', 'email', '');
+		if (!empty($email)) {
+			$link = OC_Helper::linkTo('lostpassword', 'resetpassword.php', null, true).'?user='.$_POST['user'].'&token='.$token;
+			$tmpl = new OC_Template('lostpassword', 'email');
+			$tmpl->assign('link', $link);
+			$msg = $tmpl->fetchPage();
+			$l = new OC_L10N('core');
+			mail($email, $l->t('Owncloud password reset'), $msg);
+		}
+		OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => false, 'requested' => true));
+	} else {
+		OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => true, 'requested' => false));
+	}
+} else {
+	OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => false, 'requested' => false));
+}
diff --git a/lostpassword/resetpassword.php b/lostpassword/resetpassword.php
new file mode 100644
index 0000000000000000000000000000000000000000..1a6a74e5ff403848bdcfac2810e48b7e0fd1e825
--- /dev/null
+++ b/lostpassword/resetpassword.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+*/
+
+$RUNTIME_NOAPPS = TRUE; //no apps
+require_once('../lib/base.php');
+
+// Someone wants to reset their password:
+if(isset($_GET['token']) && isset($_GET['user']) && OC_Preferences::getValue($_GET['user'], 'owncloud', 'lostpassword') === $_GET['token']) {
+	if (isset($_POST['password'])) {
+		if (OC_User::setPassword($_GET['user'], $_POST['password'])) {
+			OC_Preferences::deleteKey($_GET['user'], 'owncloud', 'lostpassword');
+			OC_Template::printGuestPage('lostpassword', 'resetpassword', array('success' => true));
+		} else {
+			OC_Template::printGuestPage('lostpassword', 'resetpassword', array('success' => false));
+		}
+	} else {
+		OC_Template::printGuestPage('lostpassword', 'resetpassword', array('success' => false));
+	}
+} else {
+	// Someone lost their password
+	OC_Template::printGuestPage('lostpassword', 'lostpassword', array('error' => false, 'requested' => false));
+}
diff --git a/lostpassword/templates/email.php b/lostpassword/templates/email.php
new file mode 100644
index 0000000000000000000000000000000000000000..d146d8e4c373aa481798546ad275e8eb84a1cdff
--- /dev/null
+++ b/lostpassword/templates/email.php
@@ -0,0 +1 @@
+<?php echo str_replace('{link}', $_['link'], $l->t('Use the following link to reset your password: {link}')) ?>
diff --git a/core/templates/lostpassword.php b/lostpassword/templates/lostpassword.php
similarity index 75%
rename from core/templates/lostpassword.php
rename to lostpassword/templates/lostpassword.php
index 67e34164d0815543821e8acf2ec69f02901b27e2..2c38a1562fe4808c21cd00377fd9bc24888530ae 100644
--- a/core/templates/lostpassword.php
+++ b/lostpassword/templates/lostpassword.php
@@ -1,4 +1,4 @@
-<form action="index.php?lostpassword" method="post">
+<form action="index.php" method="post">
 	<fieldset>
 		<?php echo $l->t('You will receive a link to reset your password via Email.'); ?>
 		<?php if ($_['requested']): ?>
@@ -7,8 +7,8 @@
 			<?php if ($_['error']): ?>
 				<?php echo $l->t('Login failed!'); ?>
 			<?php endif; ?>
-			<input type="text" name="user" id="user" placeholder="<?php echo $l->t('Username or Email'); ?>" value="" autocomplete="off" required autofocus />
+			<input type="text" name="user" id="user" placeholder="<?php echo $l->t('Username'); ?>" value="" autocomplete="off" required autofocus />
 			<input type="submit" id="submit" value="<?php echo $l->t('Request reset'); ?>" />
 		<?php endif; ?>
 	</fieldset>
-</form>
\ No newline at end of file
+</form>
diff --git a/core/templates/resetpassword.php b/lostpassword/templates/resetpassword.php
similarity index 56%
rename from core/templates/resetpassword.php
rename to lostpassword/templates/resetpassword.php
index 2f43a93cfb595a7d7b7025f370c5786ff6c200d6..3ab9dd6543c7611048d534e2578d94faa61d4a68 100644
--- a/core/templates/resetpassword.php
+++ b/lostpassword/templates/resetpassword.php
@@ -1,7 +1,8 @@
-<form action="<?php echo 'index.php?'.$_SERVER['QUERY_STRING']; ?>" method="post">
+<form action="<?php echo 'resetpassword.php?'.$_SERVER['QUERY_STRING']; ?>" method="post">
 	<fieldset>
 		<?php if($_['success']): ?>
-			<?php echo $l->t('Your password was reset'); ?>
+			<h1><?php echo $l->t('Your password was reset'); ?></h1>
+			<p><a href="<?php echo OC::$WEBROOT ?>/"><?php echo $l->t('To login page'); ?></a></p>
 		<?php else: ?>
 			<input type="password" name="password" id="password" placeholder="<?php echo $l->t('New password'); ?>" value="" required />
 			<input type="submit" id="submit" value="<?php echo $l->t('Reset password'); ?>" />
diff --git a/settings/ajax/lostpassword.php b/settings/ajax/lostpassword.php
new file mode 100644
index 0000000000000000000000000000000000000000..a2dfc0332065fd924076725e995f52bc0c194c9b
--- /dev/null
+++ b/settings/ajax/lostpassword.php
@@ -0,0 +1,19 @@
+<?php
+
+// Init owncloud
+require_once('../../lib/base.php');
+
+OC_JSON::checkLoggedIn();
+
+$l=new OC_L10N('core');
+
+// Get data
+if( isset( $_POST['email'] ) ){
+	$email=trim($_POST['email']);
+	OC_Preferences::setValue(OC_User::getUser(),'settings','email',$email);
+	OC_JSON::success(array("data" => array( "message" => $l->t("email Changed") )));
+}else{
+	OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") )));
+}
+
+?>
diff --git a/settings/js/personal.js b/settings/js/personal.js
index 9578fb2c890c1f06a4dc81e8fe93ac33cf750d9d..8108da433c80baefdfbe2a7f3fb9a480ac053ab0 100644
--- a/settings/js/personal.js
+++ b/settings/js/personal.js
@@ -32,6 +32,15 @@ $(document).ready(function(){
 
 	});
 
+	$('#lostpassword #email').blur(function(event){
+		event.preventDefault();
+		OC.msg.startSaving('#lostpassword .msg');
+		var post = $( "#lostpassword" ).serialize();
+		$.post( 'ajax/lostpassword.php', post, function(data){
+			OC.msg.finishedSaving('#lostpassword .msg', data);
+		});
+	});
+
 	$("#languageinput").chosen();
 
 	$("#languageinput").change( function(){
diff --git a/settings/personal.php b/settings/personal.php
index 05dbda473acdb913b1c37960c99e561de449a834..687b1a7aa348e53c0f5674b5e77d6a2289399fd6 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -19,6 +19,8 @@ $free=OC_Filesystem::free_space();
 $total=$free+$used;
 $relative=round(($used/$total)*10000)/100;
 
+$email=OC_Preferences::getValue(OC_User::getUser(), 'settings','email','');
+
 $lang=OC_Preferences::getValue( OC_User::getUser(), 'core', 'lang', 'en' );
 $languageCodes=OC_L10N::findAvailableLanguages();
 //put the current language in the front
@@ -35,6 +37,7 @@ $tmpl = new OC_Template( "settings", "personal", "user");
 $tmpl->assign('usage',OC_Helper::humanFileSize($used));
 $tmpl->assign('total_space',OC_Helper::humanFileSize($total));
 $tmpl->assign('usage_relative',$relative);
+$tmpl->assign('email',$email);
 $tmpl->assign('languages',$languages);
 
 $forms=OC_App::getForms('personal');
diff --git a/settings/templates/personal.php b/settings/templates/personal.php
index 4406c080edc603d99b3fa5e100eec0edd126a835..3c4ad085165a322cd3556e924cd9cc373ccbe384 100644
--- a/settings/templates/personal.php
+++ b/settings/templates/personal.php
@@ -19,6 +19,14 @@
 	</fieldset>
 </form>
 
+<form id="lostpassword">
+	<fieldset class="personalblock">
+		<label for="email"><strong><?php echo $l->t('Email');?></strong></label>
+		<input type="text" name="email" id="email" value="<?php echo $_['email']; ?>" placeholder="<?php echo $l->t('Your email address');?>" /><span class="msg"></span><br />
+		<em><?php echo $l->t('Fill in an email address to enable password recovery');?></em>
+	</fieldset>
+</form>
+
 <form>
 	<fieldset class="personalblock">
 		<label for="languageinput"><strong><?php echo $l->t('Language');?></strong></label>