Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > retrieve security question from custom user setting View modes: 
User avatar
Member
Member
rafik - 11/25/2013 8:00:21 AM
   
retrieve security question from custom user setting
Hi guys,

I am customizing the LogonForm web parts. If the user forget his password, he will press on "I forget my password" then he will enter his username then he will press send. But when he will press send, I want the system retrieve his security question from user setting (SecurityQuestion field) and he put the answer he put inside already. I am trying to add in btnPasswdRetrieval_Click the security question but I am trying to assign his username or email he put in txtPasswordRetrieval to the username or email in user table or user setting to see if it's much, then get security question from his user setting. But I failed. Can someone help me please I tried to follow the documentation bu no success.

Thanks guys

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/26/2013 5:37:16 AM
   
RE:retrieve security question from custom user setting
Hello,

Thank you for your message.

May I ask what documentation have you followed and which exact step are you stucked on?

If you want to get some information from the user table I tested the following inside the txtPasswordRetrieval function of the LogonForm webpart before the ForgottenEmailRequest email request.

I was able to pullout user information with following:

UserInfo myUser = UserInfoProvider.GetUserInfo(value);
if (myUser != null)
{
string email = myUser.GetStringValue("Email", "answer is not there..");
// do your code
}
else
{
// user info is null -> user was not found
// do your code
}


I was trying to get the Email value for my testing purposes, you will need to pullout the security question column and than compare the answer with question. You will also need to add an additional text box which will show along with the text box for user name or e-mail.

Please let me know if you have further questions.

Kind regards,
Richard Sustek

User avatar
Member
Member
rafik - 11/26/2013 12:00:39 PM
   
RE:retrieve security question from custom user setting
Thanks Richard, I resolve the issue to get the security question by adding
UserInfo myUser = UserInfoProvider.GetUserInfo(value); in my code (that what I was missing).

Now I have 2 others questions :

First question: now let's say the user put email instead of username then what can I use instead of GetUserInfo(Username).

Second question: now the question show up and the user put the security answer. But how can I validate the security answer in custom user. Also I am trying to figure out to make it by 2 txtPasswordRetrieval function buttons clicks or keep it in the same txtPasswordRetrieval function. Because when the user enter his username and press submit, the system will return a security question then the user enter his security answer then he will need to submit again.

My best regards
Rafik

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/28/2013 4:35:06 AM
   
RE:retrieve security question from custom user setting
Hi,

There is not an API method to get the UserInfo based on e-mail, but I was able to accomplish with a custom query where I get the UserName based on e-mail and you can then use the UserName to get the UserInfo as in the previous e-mail.

The code for this is:
string sql = "SELECT UserName From dbo.CMS_User where Email = 'administrator@localhost.local'";
DataSet ds = CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(sql, null, QueryTypeEnum.SQLQuery);
DataRow dr = ds.Tables[0].Rows[0];
string UserName = dr.ItemArray.GetValue(0).ToString();


You will have to distinquish whether the user put an e-mail or not and based on that proceed with the code.

To answer your second question -> You should be ok with using simple If functionality and comparing answer with question. I would also recommend using trimmed values.

Kind regards,
Richard Sustek


User avatar
Member
Member
rafik - 12/1/2013 3:52:28 PM
   
RE:retrieve security question from custom user setting
Hi Richard,

Thank you for your help,

About security Questions and answers, I fixed it work well now.

But about searching by Email and not username I didn't have success to make it work.

I tried two ways the first is like you writed to see the result if it will be success but no and I tried another way but also no success

The first way

string sql = "SELECT UserName From dbo.CMS_User where Email = 'test@local' "; DataSet ds = CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(sql, null, QueryTypeEnum.SQLQuery); DataRow dr = ds.Tables[0].Rows[0]; string UserName = dr.ItemArray.GetValue(0).ToString();

if (UserName != null)
{
UsernameText.Text = UserName;
}



The second way the one I need the most

string value1 = txt2PasswordRetrieval.Text.Trim();
string sql = "SELECT UserName From dbo.CMS_User where Email =" +value1; DataSet ds = CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(sql, null, QueryTypeEnum.SQLQuery); DataRow dr = ds.Tables[0].Rows[0]; string UserName = dr.ItemArray.GetValue(0).ToString();

if (UserName != null)
{
UsernameText.Text = UserName;
}


But no success as result to retrieve the username from email

Can you help me about this one please

My best regards

User avatar
Member
Member
kentico_sandroj - 12/1/2013 4:16:36 PM
   
RE:retrieve security question from custom user setting
Hello,

Please check if the e-mail exists in the CMS_User table. If it does, please debug the code and let us know where the data is missing. Is the DS empty or DR empty? This is likely an issue with the SQL query format.

Regards,
Sandro

User avatar
Member
Member
rafik - 12/6/2013 9:25:22 AM
   
RE:retrieve security question from custom user setting
Thanks Sandro,

I get issue with running the debugging because it was visual studio 2013, anyway I fixed by adding <add key="PageInspector:ServerCodeMappingSupport" value="Disabled"/> in <appsettings> in webconfig.

Anyway it was SQL query format syntax. I resolve my issue in following code
            string sql = "SELECT UserName From dbo.CMS_User where Email =" + "'" + value1 + "'";
DataSet ds = CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(sql, null, QueryTypeEnum.SQLQuery);
DataRow dr = ds.Tables[0].Rows[0];
string UserName = dr.ItemArray.GetValue(0).ToString();


Thank you guys again for your best support.