We use more and more social websites and portals, creating many user profiles in the process. But how many usernames can we possibly remember? The usernames we choose during the account registration process are often forgotten.
Is there no easier way to log on?
In fact, there are lots of possibilities. First of all, we could make use of OpenID, although I still have reservations to using the same login parameters in all websites in which I regularly participate. TYPO3 provides a simple solution by allowing the user to provide either an email address or a username. Usernames tend to be forgotten, but it’s much harder to lose track of your email address ;)
Username-based login is a standard feature in TYPO3, whereas the ability to use either a username or an email address in the login field needs to be programmed in. Read on to find out how to easily implement this feature through a TYPO3
What are Typo3 services?
TYPO3 services are a collection of other classes available in plug-ins or in the TYPO3 core. They are designed for easy description, expansion and upgrade while completely maintaining normal TYPO3 behaviour.
In our case, we will take a look at the authentication service and expand the tx_sv_authbase class with the support for user authentication via “username” or “email” fields from the fe_users table.
We are going to start by creating a new basic plug-in in a kickstarter, or by selecting another plug-in that we will use for user authentication. A function for creating a basic service class in inbuilt in the kickstarter. However, to make the process clearer, I omitted this step during the creation of my custom_signon plug-in.
Service registration
Let's open the ext_localconf.php file in our custom_signon plug-in and append the following code:
#ext_localconf.php t3lib_extMgm::addService($_EXTKEY, 'auth' /* sv type */, 'tx_customsignon_sv1' /* sv key */, 'description' => 'Allow email as username', 'subtype' => 'getUserFE,authUserFE', 'available' => TRUE, 'priority' => 50, 'quality' => 50, 'os' => '', 'exec' => '', 'classFile' => t3lib_extMgm::extPath($_EXTKEY).'sv1/class.tx_customsignon_sv1.php', 'className' => 'tx_customsignon_sv1', ) );
Descriptions of all table parameters can be found here: typo3.org/documentation/document-library/core-documentation/doc_core_services/1.0.1/view/1/4/
Upon registering the service, we can start creating the class.tx_customsignon_sv1.php file and the tx_sv_auth class extension. We will require two functions: getUser and authUser.
The getUser function is collecting the user, who entered his or her email or username in the username field, from the fe_users table.
#class.tx_customsignon_sv1.php function getUser() { $user = false; if ($this->login['status']=='login' AND $this->login['uident']) { $login = $this->login['uname']; $login = $GLOBALS['TYPO3_DB']->quoteStr($login, "fe_users"); $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery( '*', 'fe_users', "(email = '$login' OR username = '$login') ".$this->db_user['enable_clause'] ); $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres); } return $user; }
The user is then authenticated through the authUser function
#class.tx_customsignon_sv1.php function authUser($user) { $OK = 100; if ($this->login['uident'] && $this->login['uname']) { // Checking password match for user: $OK = $this->compareUident($user, $this->login); // Checking the domain (lockToDomain) if ($OK && $user['lockToDomain'] && $user['lockToDomain']!=$this->authInfo['HTTP_HOST']) { $OK = false; } } return $OK; }
Download files:

Latest comments
Daniel
I get a fatal error with this extension: Fatal error: Call to undefined method t3lib_div::makeInsta... / 07 May. 20:53
Zaawansowana subskrypcja, nasze nowe rozszerzenie
Michael
The correct Amazon S3 API TER link is http://typo3.org/extensions/repository/view/amazon-s3-api T... / 24 Apr. 11:44
s3example - TYPO3 i Amazon S3
Adi
Pod nową wersją t3 z gałęzi 4.5.14 (gdzie w korze znalazły się jakieś krytyczne luki) wtyczka też ni... / 02 Apr. 19:52
Zaawansowana subskrypcja, nasze nowe rozszerzenie
Rafał Brzeski
Nasze niedopatrzenie, w nowej wersji dodamy opcję wyboru tej opcji. / 21 Mar. 20:22
Zaawansowana subskrypcja, nasze nowe rozszerzenie
bocianos
Wszystko super tylko jak zrobic aby nowe adresy domyslnie miały zaznaczone otrzymywani maili w forma... / 20 Mar. 13:08
Zaawansowana subskrypcja, nasze nowe rozszerzenie