General - .NET User Groups General issues with editing, development and graphic design.
Kentico CMS for .NET User Groups > General - .NET User Groups > Problem with GetPassword on CMSMembershipUser View modes: 
User avatar
Member
Member
olivier-insumma - 10/30/2009 11:16:55 AM
   
Problem with GetPassword on CMSMembershipUser
We are using the kentico software to create a easily used survey site.
A common feature for a survey site is to be able to upload a list of users and after that send a mass e-mail to all the users that are going to use the survey with their username and password.

We created a module where users can be uploaded through a csv file. Now we are building the mass e-mail part. functionality:
- Select a group of users.
- Type E-mail tekst
- Be able to use the markers <%Fullname%>, <%Username%>, <%Password%> (for the mail merge).

When we call GetPassword() on the CMSMembershipUser we get a strange error:

Key cannot be null.

After some investigation we noticed that although we set te password format on cleartext in the web.config it always saves the password hashed. We know there is no way the retreive a hashed password.
How can we solve this problem? (For example can we save the password in clear text/encrypted?)

Code example:
UserInfo ui = UserInfoProvider.GetUserInfo(ValidationHelper.GetInteger(dr["MemberUserID"], 0));
if (ui != null)
{
string EmailContent = txtEmailContent.Text.Replace(sFullName, ui.FullName);
EmailContent = EmailContent.Replace(sUserName, ui.UserName);
CMSMembershipUser muser = new CMSMembershipUser(ui);
EmailContent = EmailContent.Replace(sPassword, muser.GetPassword());
}

Exception:
Key cannot be null.
Parameter name: key

at System.Collections.Hashtable.get_Item(Object key)
at System.Configuration.Provider.ProviderCollection.get_Item(String name)
at System.Web.Security.MembershipProviderCollection.get_Item(String name)
at System.Web.Security.MembershipUser.GetPassword()
at CMSModules_CorrelatieRekenmodule_Default.CreateMailingList() in d:\Projects\DirectGovernance-Calibratie\KenticoCMS\CMSModules\SurveyUsers\Default.aspx.cs:line 318
at CMSModules_CorrelatieRekenmodule_Default.btnSend_Click(Object sender, EventArgs e) in d:\Projects\DirectGovernance-Calibratie\KenticoCMS\CMSModules\SurveyUsers\Default.aspx.cs:line 56
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Kind regards,
Olivier v/d Rhoer

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 11/5/2009 1:45:55 AM
   
RE:Problem with GetPassword on CMSMembershipUser
Hello,

Kentico CMS doesn't use classic membership settings in web.config but the format is specified in 'Site Manager -> Settings -> select global in dropdown -> Security -> Password Format' field. You can choose 'plain text' option and then use following sample code to get password:
object password = ui.GetValue("UserPassword");

Best Regards,
Martin Dobsicek

User avatar
Member
Member
olivier-insumma - 11/5/2009 1:48:59 AM
   
RE:Problem with GetPassword on CMSMembershipUser
Thanks, this fixed my problem!