By Anonymous (not verified) on
i am new to drupal kindly tell me what i am missing in this code....i am trying to log in via email but when i try it shows error
"Sorry, unrecognized username or password. Have you forgotten your password?"....kindly guide me how to do it..
function abhinav_form_alter(&$form, &$form_state, $form_id)
{
if($form_id=='user_login')
{
$form['name'] = array
(
'#type' => 'textfield',
'#title' => t('Username/ Email Address'),
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
);
$form['#submit'][] = 'abhinav_login_submit';
}
if($form_id== 'user_login_block')
{
$form['name'] = array
(
'#type' => 'textfield',
'#title' =>t('Username/ Email Address'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#size' => 15,
'#required' => TRUE,
);
$form['#submit'][] = 'abhinav_login_submit';
}
}
function abhinav_login_submit($form,&$form_state)
{
$name=$form_state['values']['name'];
$pass=$form_state['values']['pass'];
//$param = md5($pass);
$query=db_query("select uid,name,mail,pass from {users} where name='%s' or mail='%s' ",$name,$name);
$result= db_fetch_array($query);
$auth = array
(
'pass' => $pass,
'name' => $result['name'],
);
if (user_authenticate($auth))
{
$form_state['redirect'] = 'user/'. $account->uid;
}
}
Comments
Hello, The best way to go
Hello,
The best way to go with is try the logintoboggan module..
http://drupal.org/project/logintoboggan
thx 4 the reply
actually i want to learn the drupal functionality ,i mean how it work... thats why m nt using any module i m familiar with the logintoboggan module.....i want it through the coding only dear kindly help me
Hi, Be default the user_login
Hi,
Be default the user_login validators like 'user_login_name_validate' etc are executed before your submit handlers and hence these things will still substitute the 'email' to the 'name' field, so your validation keeps on failing. In order to aviod that you need to flip the username for the entered email in your custom validator. Add the bewlo code in your form_alter
Now the 'name' element will contains the actual username for the corresponding email address. So automatically all the validations will get succeded. No need to add anything in the submit handler (so remove the function abhinav_login_submit()) since the default user_login will redirect the user to the correspoding user's page. Hope you understand the logic.
thx it worked.............
thx a lot..........