Magento Coding Solutions

magento login programmatically

<?php $email="customer email address";
 $password="customer password";

 $session = Mage::getSingleton('customer/session');
 $message=""; //error message to add to session

 try {
  $session->login( $email, $password );
  if ($session->getCustomer()->getIsJustConfirmed()) {
  //Customer is confirmed and successfully logged in
  }
 } catch (Mage_Core_Exception $e) {
  //error occured
  switch ($e->getCode()) {
  case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
  //email not confirmed actions here
  break;
  case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
  //Email or password invalid actions here
  $message = $e->getMessage();//echo the error message
  break;
  default:
  $message = $e->getMessage(); //Display other error messages
  }
  $session->addError($message);
 } catch (Exception $e) {
  //login failed because of some other error.
 }?>

magento user registration programmatically

$customer_email = 'test@testemail.com'; 
$customer_fname = 'test_firstname';    
$customer_lname = 'test_lastname';     
$passwordLength = 10;


$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->setEmail($customer_email);
$customer->setFirstname($customer_fname);
$customer->setLastname($customer_lname);
$customer->setPassword(md5());
$customer->save();