+ Start a Discussion
sfdotcomsfdotcom 

how to generate a paasword which is same as username using apex & visualforce?

I want the Visualforce code for creating login form & whenever user create the account, form should automatically  generating new password same as username & password should be sent in email.?

plz give me code for above task. i need it.

thanks in advance..............
praveen murugesanpraveen murugesan
Hi,

Refer this link for login page:

https://success.salesforce.com/answers?id=90630000000h2reAAA

EG:
<apex:page controller="LoginPages" showHeader="false" sidebar="false" standardStylesheets="true">
<apex:Pagemessages id="msg"/>
<apex:form >
<p><b>Login Page</b><br /></p>
<apex:panelGrid columns="2" style="margin-top:1em;">
<p><b>UserName</b><br />
<apex:inputText required="true" id="username" value="{!username}"/>
</p>
<p><b>Password</b><br />
<apex:inputSecret id="password" value="{!password}"/>
</p>
<apex:commandButton action="{!registerUser}" value="Register" id="register"  immediate="true"/>
  <apex:commandButton action="{!registerUser}" value="Save" id="save"/>
   <apex:commandButton action="{!registerUser}" value="Cancel" id="cancel"/>
</apex:panelGrid>
</apex:form>
</apex:page>

Controller:

public class LoginPages {

    public String password { get; set; }
    public String username { get; set; }
   
    public PageReference registerUser() {
        PageReference newPage = new PageReference('/apex/newPage');
        newPage.setRedirect(true);
        return newPage;
    }
}

To send the email refer this

http://www.salesforce.com/us/developer/docs/pages/Content/pages_email_custom_controller.htm
EG:

Case c = new Case();
insert c;

EmailMessage e = new EmailMessage();
e.parentid = c.id;
// Set to draft status.
// This status is required
// for sendEmailMessage().
e.Status = '5';
e.TextBody =
  'Sample email message.';
e.Subject = 'Apex sample';
e.ToAddress = 'customer@email.com';
insert e;

List<Messaging.SendEmailResult>
  results =
  Messaging.sendEmailMessage(new ID[]
    { e.id });

System.assertEquals(1, results.size());
System.assertEquals(true,
                    results[0].success);

Mark this as best answer if its helps..

Thanks

Praveen Murugesan