×
Namespaces

Variants
Actions
(Difference between revisions)

Creating a password dialog with secret editors using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
m (Protected "Creating a password dialog with secret editors" [edit=sysop:move=sysop])
hamishwillee (Talk | contribs)
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
+
{{ArticleMetaData <!-- v1.2 -->
__NOEDITSECTION__
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|devices= Nokia N93
|-
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|'''ID''' || &nbsp;
+
|platform= S60 3rd Edition, FP1
|'''Creation date''' || June 10, 2008
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|-
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Platform''' || S60 3rd Edition, FP1
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|'''Tested on devices''' || Nokia N93
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|-
+
|keywords= CAknMultiLineDataQueryDialog, CAknTextQueryDialog, NUMSECRETED, SECRETED, CAknMultiLineDataQueryDialog::ExecuteLD, CAknTextQueryDialog::ExecuteLD
|'''Category''' || Symbian C++
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
|'''Subcategory''' || Files/Data
+
|translated-by= <!-- [[User:XXXX]] -->
|}
+
|translated-from-title= <!-- Title only -->
 
+
|translated-from-id= <!-- Id of translated revision -->
 
+
|review-by= <!-- After re-review: [[User:username]] -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
|-
+
|update-by= <!-- After significant update: [[User:username]]-->
|'''Keywords (APIs, classes, methods, functions):''' CAknMultiLineDataQueryDialog, CAknTextQueryDialog, NUMSECRETED, SECRETED, CAknMultiLineDataQueryDialog::ExecuteLD, CAknTextQueryDialog::ExecuteLD
+
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|}
+
|creationdate= 20080610
 +
|author= [[User:Aknyman]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Files/Data
 +
|id= CS001056
 +
}}
  
 
==Overview==
 
==Overview==
This code snippet shows how to create a password dialog with secret editors. Numeric secret editors can be defined using NUMSECRETED resource structure in a resource file and alphanumeric secret editors are defined using a SECRETED resource structure. This code snippet implements two example dialogs with SECRETED structures. The first one is a multiline query dialog containing password and confirmation fields and the second one is a simple text query dialog with one password field.   
+
This code snippet shows how to create a password dialog with secret editors. Numeric secret editors can be defined using s NUMSECRETED resource structure in a resource file and alphanumeric secret editors are defined using a SECRETED resource structure. This code snippet implements two example dialogs with SECRETED structures. The first one is a multiline query dialog containing password and confirmation fields and the second one is a simple text query dialog with one password field.   
  
 
This snippet can be self-signed.
 
This snippet can be self-signed.
Line 30: Line 35:
  
 
<code>
 
<code>
LIBRARY     avkon.lib  //Avkon resources
+
LIBRARY avkon.lib  //Avkon resources
 
</code>
 
</code>
  
Line 274: Line 279:
  
 
==Postconditions==
 
==Postconditions==
 +
The example code shows a password and confirmation dialog to the user and stores the given password into the member variable iPassword. After this, a simple password query dialog is shown to the user.
  
The example code shows a password and confirmation dialog to the user and stores the given password into the member variable iPassword, after that a simple password query dialog is shown to the user. 
+
[[Category:Symbian C++]][[Category:Code Snippet]][[Category:Files/Data]][[Category:Code Snippet]]
 
+
==See also==
+
 
+
[[Category:Symbian C++]][[Category:Code Examples]][[Category:Files/Data]]
+

Revision as of 09:16, 13 June 2012

Article Metadata
Tested with
Devices(s): Nokia N93
Compatibility
Platform(s): S60 3rd Edition, FP1
Article
Keywords: CAknMultiLineDataQueryDialog, CAknTextQueryDialog, NUMSECRETED, SECRETED, CAknMultiLineDataQueryDialog::ExecuteLD, CAknTextQueryDialog::ExecuteLD
Created: aknyman (10 Jun 2008)
Last edited: hamishwillee (13 Jun 2012)

Contents

Overview

This code snippet shows how to create a password dialog with secret editors. Numeric secret editors can be defined using s NUMSECRETED resource structure in a resource file and alphanumeric secret editors are defined using a SECRETED resource structure. This code snippet implements two example dialogs with SECRETED structures. The first one is a multiline query dialog containing password and confirmation fields and the second one is a simple text query dialog with one password field.

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY avkon.lib   //Avkon resources


Resource file

.rss

#define KMaxPasswordLength 10
 
RESOURCE DIALOG r_dialog_password_and_confirmation_query
{
flags = EGeneralQueryFlags;
 
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtMultilineQuery;
id = EMultilineFirstLine;
control = AVKON_DATA_QUERY
{
layout = EMultiDataFirstSecEd;
label = "Enter Password:";
control = SECRETED
{
num_letters = KMaxPasswordLength;
};
};
},
DLG_LINE
{
type = EAknCtMultilineQuery;
id = EMultilineSecondLine;
control = AVKON_DATA_QUERY
{
layout = EMultiDataSecondSecEd;
label = "Confirm Password:";
control = SECRETED
{
num_letters = KMaxPasswordLength;
};
};
}
};
}
 
 
RESOURCE DIALOG r_dialog_password_query
{
flags = EAknGeneralQueryFlags;
 
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EGeneralQuery;
control = AVKON_DATA_QUERY
{
layout = ECodeLayout;
label = "Enter Password:";
control = SECRETED
{
num_letters = KMaxPasswordLength;
};
};
}
};
}


Header file

#ifndef __PASSWORDAPPUI_H__
#define __PASSWORDAPPUI_H__
 
const TInt KMaxPasswordLength = 10;
//...
 
class CPasswordAppUi : public CAknAppUi
{
//...
private:
//...
TBool ShowPasswordAndConfirmationDialogL(TDes& aPassword);
TBool ShowPasswordDialogL(TDes& aPassword);
void UsePasswordDialogsL(); //a test method for dialogs
private:
//...
HBufC* iPassword;
};
 
#endif // __PASSWORDAPPUI_H__


Source file

#include <AknQueryDialog.h>
#include <Password_0xE0859401.rsg>
 
//...
CPasswordAppUi::CPasswordAppUi():iPassword(NULL)
{
}
 
CPasswordAppUi::~CPasswordAppUi()
{
//...
if (iPassword)
{
delete iPassword;
iPassword=NULL;
}
}
 
TBool CPasswordAppUi::ShowPasswordAndConfirmationDialogL(TDes& aPassword)
{
TBuf<KMaxPasswordLength> password;
TBuf<KMaxPasswordLength> confirmation;
 
CAknMultiLineDataQueryDialog* dlg =
CAknMultiLineDataQueryDialog::NewL(password, confirmation);
 
if (!dlg->ExecuteLD(R_DIALOG_PASSWORD_AND_CONFIRMATION_QUERY))
{
//Cancel key pressed
//do something...
return EFalse;
}
else
{
if(password.Compare(confirmation) == 0)
{
//password and confirmedPassword match.
//do something...
 
aPassword.Copy(password);
return ETrue;
}
else if(password.Length() != confirmation.Length())
{
//password buffer and confirmation buffer have different lengths
//do something...
 
return EFalse;
}
else
{
//password buffer and confirmation buffer have different contents
//do something...
 
return EFalse;
}
}
}
 
TBool CPasswordAppUi::ShowPasswordDialogL(TDes& aPassword)
{
TBuf<KMaxPasswordLength> password;
 
CAknTextQueryDialog* dlg =
new(ELeave) CAknTextQueryDialog(password, CAknQueryDialog::ENoTone );
 
if(!dlg->ExecuteLD(R_DIALOG_PASSWORD_QUERY))
{
//Cancel key pressed
//do something...
return EFalse;
}
else
{
//OK do something...
aPassword.Copy(password);
return ETrue;
}
}
 
 
void CPasswordAppUi::UsePasswordDialogsL()
{
//reset old password if exists
if(iPassword)
{
delete iPassword;
iPassword=NULL;
}
 
iPassword = HBufC::NewL(KMaxPasswordLength);
TPtr bufPtr = iPassword->Des();
 
//show password and confirmation dialog and store the given
//password in member variable iPassword if input values are ok
TBool ret = ShowPasswordAndConfirmationDialogL(bufPtr);
 
if(ret)
{
//create a temporary buffer to store the given password
HBufC* tmpPassword = HBufC::NewLC(KMaxPasswordLength);
TPtr tmpPtr = tmpPassword->Des();
 
//show a password dialog
TBool ret2 = ShowPasswordDialogL(tmpPtr);
 
if(ret2)
{
//compare the given password with member variable iPassword
if (tmpPassword->Compare(*iPassword) == 0)
{
//passwords match ok, do something....
}
else
{
//The given password is not correct, do something...
}
}
else
{
//the user pressed cancel, there is no password to compare
//do something...
}
 
CleanupStack::PopAndDestroy(); //tmpPassword
}
else
{
//giving a new password failed, do something...
delete iPassword;
iPassword=NULL;
}
}


Postconditions

The example code shows a password and confirmation dialog to the user and stores the given password into the member variable iPassword. After this, a simple password query dialog is shown to the user.

118 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×