enter image description here

public with sharing class gmController {
public gmail__c g{get; set;}

    public gmController() {


public gmail__c opp{get; set;}
    public gmController(ApexPages.StandardController controller) {
opp = (gmail__c)controller.getRecord();
g=new gmail__c ();

public gmail__c reg{get; set;}
public list<gmail__c> gmailuser{get; set;}
public Boolean Match{get; set;}
public Boolean NotMatch{get; set;}

PageReference pageRef;
public PageReference signin(){

gmailuser=new list<gmail__c>();
string s=opp.USERNAME__c;
string p=opp.password__c;
string x=[select USERNAME__c from gmail__c where USERNAME__c =: opp.USERNAME__c].USERNAME__c;
string y=[select password__c from gmail__c where password__c =: opp.password__c].password__c;

if(x!=null & y!=null){

 if(s==x & p==y ){

 pageRef=new PageReference('/apex/welcom');
return pageRef;

return pageRef;

public PageReference forgotpassword(){
PageReference forppage= null;
        forppage= Page.customizeloginpage;
        return Page.forppage;


public PageReference save(){
insert g;
PageReference p=new PageReference('/apex/forpage');
return p;
}public boolean displayPopup {get; set;}     

    public void closePopup() {        
        displayPopup = false;    
    public void showPopup() {     
        displayPopup = true; 

    public string getpword(){

    string y=[select password__c from gmail__c where USERNAME__c =:opp.USERNAME__c].password__c;

return opp.password__c=y;


<apex:page standardController="gmail__c" extensions="gmController">
<apex:form >
function myFunction() {
    var myWindow = window.open("https://c.ap2.visual.force.com/apex/windowpopup", "MsgWindow", "width=600,top=100,left=350, height=490");

<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock >
<apex:pageBlockSection columns="1">

<apex:pageBlockSectionItem >
<apex:outputLabel value="User Name" for="resource" />
<apex:inputField value="{!gmail__c.USERNAME__c}" id="resource"/>

<apex:pageBlockSectionItem >
<apex:outputlabel value="Password" for="password"/>
<apex:inputSecret value="{!gmail__c.password__c}"  id="password"/>


<apex:pageblockButtons location="bottom">
<apex:commandButton value="login" action="{!signin}" reRender="notmatch"/>
<apex:commandButton value="Register" onclick="myFunction();" rerender="tstpopup"/>
<apex:commandLink value="forgotpassword" action="{!forgotpassword}" />

<apex:outputPanel id="tstpopup">
        <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
                This isthe popup windowr.<br/><br/><br/>

                <apex:outputLabel value="name"><apex:inputField value="{!g.Name}"/></apex:outputLabel><br/>
                <apex:outputLabel value="username"><apex:inputField value="{!g.USERNAME__c}"/></apex:outputLabel><br/>
                <apex:outputLabel value="password"><apex:inputSecret value="{!g.password__c}"/></apex:outputLabel><br/>
                <apex:commandButton value="save from here" action="{!save}"/>
                <apex:commandButton value="Hide Pop up" action="{!closePopup}" rerender="tstpopup"/>
        <style type="text/css">
            background-color: white;
            border-width: 4px;
            border-style: solid;
            z-index: 9999;
            left: 50%;
            position: absolute;
            /* These are the 3 css properties you will need to change so the popup 
            displays in the center of the screen. First set the width. Then set 
            margin-left to negative half of what the width is. You can add 
            the height property for a fixed size pop up if you want.*/
            width: 500px;
            margin-left: -250px;
            opacity: 0.20;
            filter: alpha(opacity = 20);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;

the problem is with login action.if i give the credentials that are not exixts in the database,then give giving the error.if i give the credentials that are exists in database,,works fine.

  • Are you seriously storing password as plaintext ? – karthikselva Feb 11 '16 at 7:10
  • Iam fresher,I would really appreciate some help in solving this – Satya Feb 11 '16 at 7:10
  • yes mr.karthikselva – Satya Feb 11 '16 at 7:14
  • 1
    plaintextoffenders.com/about – Keith C Feb 11 '16 at 9:13
  • sir,my issuse is not with the plaintext or something else,if login with the details that are not available in the database,then it gives error at line 24(variable x,if username is not available)and for password also,(if password is not available in database then it is throwing exception at line 25 variable y) – Satya Feb 11 '16 at 9:31

The reason you are getting exceptions is that the queries may not find the record

string x=[select USERNAME__c from gmail__c where USERNAME__c =: opp.USERNAME__c].USERNAME__c;

One way around this is as follows

Gmail__c[] gmXList = [select username__c from gmail__c where username__c = :opp.username__c];
if (gmXList.size() == 1) {.. normal processing flow}
if (gmXList.size() > 1) {...error? .. choose most recent? ... }
else { ..error - no User found}
| improve this answer | |
  • it is not working sir list<User[]> cannot be asigned to list<gmail__c> – Satya Feb 12 '16 at 7:28
  • my bad; edited answer. You really need better variable names (x and y are not very transparent). I tend to make my variable names reflective of the underlying sobject, go something like gm... for variables about custom object Gmail__c. If you stick to a convention, your coding goes faster and is less error prone – cropredy Feb 12 '16 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.