Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > forgot password adding space View modes: 
User avatar
Member
Member
eagleag - 5/18/2011 2:26:47 AM
   
forgot password adding space
Hi,
When I use FORGOT PASSWORD I recive email with new password.
When I copy paste it (from email) into PASSWORD field it add an extra space at end (also when I paste into a txt file).

And this cause to not allow login.

how can I prevent this?
If cant prevent is it possible to add a trim to password textbox?

THanks ::)

User avatar
Kentico Support
Kentico Support
kentico_radekm - 5/18/2011 2:38:26 AM
   
RE:forgot password adding space
Hello.

We recommend you to copy/paste password via some plain text editor, e.g. Notepad. This extra space is not added by Kentico, it is added when you copy password form your e-mail client. Anyway, it is not added every time, sometimes you are able to copy password string only. In any case, copy it through some plain text editor helps always. If you want check inputted string for empty space and if so, trim it, you can customize Logon form web part (\CMSWebParts\Membership\Logon\LogonForm.ascx), Login1_LoggedIn method.

Best Regards,
Radek Macalik


User avatar
Member
Member
eagleag - 5/18/2011 3:26:26 AM
   
RE:forgot password adding space
Hi
i checked this method Login1_LoggedIn and isnt hit if password incorrect, so couldn't find where to trim password.

only hits Login1_LoggingIn.

I retrieved password field by:
TextBox txt = (TextBox)Login1.FindControl("Password");

but not sure how to proceed.
Please advise.

void Login1_LoggedIn(object sender, EventArgs e)
{

// Ensure response cookie
CookieHelper.EnsureResponseCookie(FormsAuthentication.FormsCookieName);

// Set cookie expiration
if (Login1.RememberMeSet)
{
CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddYears(1), false);
}
else
{
// Extend the expiration of the authentication cookie if required
if (!UserInfoProvider.UseSessionCookies && (HttpContext.Current != null) && (HttpContext.Current.Session != null))
{
CookieHelper.ChangeCookieExpiration(FormsAuthentication.FormsCookieName, DateTime.Now.AddMinutes(Session.Timeout), false);
}
}

// Redirect user to the return url, or if is not defined redirect to the default target url
if (ValidationHelper.GetString(Request.QueryString["ReturnURL"], "") != "")
{
UrlHelper.Redirect(ResolveUrl(ValidationHelper.GetString(Request.QueryString["ReturnURL"], "")));
}
else
{
if (this.DefaultTargetUrl != "")
{
UrlHelper.Redirect(ResolveUrl(this.DefaultTargetUrl));
}
else
{
UrlHelper.Redirect(URLRewriter.CurrentURL);
}
}
}


/// <summary>
/// Ligging in handler
/// </summary>
void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
TextBox txt = (TextBox)Login1.FindControl("Password");
// Ban IP addresses which are blocked for login
if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.Login))
{
e.Cancel = true;

LocalizedLiteral failureLit = Login1.FindControl("FailureText") as LocalizedLiteral;
if (failureLit != null)
{
failureLit.Visible = true;
failureLit.Text = ResHelper.GetString("banip.ipisbannedlogin");
}
}

if (((CheckBox)Login1.FindControl("chkRememberMe")).Checked)
{
Login1.RememberMeSet = true;
}
else
{
Login1.RememberMeSet = false;
}
}



Thanks

User avatar
Kentico Support
Kentico Support
kentico_radekm - 5/31/2011 6:09:08 AM
   
RE:forgot password adding space
Hello.

Please find code example below. You can place it within a Login1_LoggingIn method. If password contains any empty character, user will be notified about it and logon process will break for that moment.

If you would like to remove any empty character automatically in Logon form, you would need a full source code for that. If you have, please let me know and I will provide a solution for you.

Code example:

bool bContainsWhiteSpace = false;
string sPassword = Login1.Password;

if (sPassword != null)
{
for (int i = 0; i < sPassword.Length; i++)
{
if (char.IsWhiteSpace(sPassword))
{
bContainsWhiteSpace = true;
}

else
{
bContainsWhiteSpace = false;
}
}
}

if (bContainsWhiteSpace)
{
Response.Write("Please remove empty space from password.");
e.Cancel = true;
}


Best Regards,
Radek Macalik