Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateUserWizard CreatingUser Issue 1

Status
Not open for further replies.

LittlBUGer

Programmer
Apr 26, 2006
81
US
Hello. I'm using ASP.NET 2.0 and I have a page that does user registration. I've had it all working fine for a while until I noticed a couple things that it wasn't checking. It wasn't checking to see if the email entered was a real email (by format) so I had to use a regularexpression validator to do so, which went fine. The other problem though, is checking the password entered to see if it contains the username entered. Thus, I would NOT want someone to register with the following info:

Username: BobbyJoe
Password: BobbyJoe1 (or bobbyjoe1)

So by going into the CreatingUser event, I think I've successfully been able to check for the username being in the password and I can call the e.Cancel = true part of it to stop the registration process from continuing, but I can't figure out how to throw up an error about this. I've tried using a label or something but nothing seems to work. Has anyone else had any similar issues? Thanks for your help.

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
OK, here's the two parts in question:

Code:
    Private Function ProcessString(ByVal pass As String, ByVal user As String) As Integer
        Dim thepass As String = pass
        Dim theuser As String = user
        Dim theuserlower As String = user.ToLower()
        Dim theresult As Integer = 0
        If thepass.IndexOf(theuser, 0) >= 0 Or thepass.IndexOf(theuserlower, 0) >= 0 Then
            theresult = 1
        End If
        Return theresult
    End Function


    Protected Sub CreateUserWizard1_CreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
        Dim theuserbox As TextBox = DirectCast(WizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
        Dim thepassbox1 As TextBox = DirectCast(WizardStep1.ContentTemplateContainer.FindControl("Password"), TextBox)
        Dim thepassbox2 As TextBox = DirectCast(WizardStep1.ContentTemplateContainer.FindControl("ConfirmPassword"), TextBox)

        Dim result As Integer = 0
        result = ProcessString(thepassbox1.Text, theuserbox.Text)
        If result = 1 Then
            lblMessage.Visible = True
            lblMessage.ForeColor = Drawing.Color.Red
            lblMessage.Text = "Password cannot contain Username. Please try again."
            e.Cancel = True
        Else
            e.Cancel = False
        End If
    End Sub

It's the lblMessage label that doesn't work. When the registration is canceled because of a password containing a username, it doesn't do anything. Meaning, when the user clicks on the Register button, the page just refreshes and blanks out the two password boxes but no error message is shown. Any ideas? Thanks.

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
first, trace through your code to see if the code is executed the way you expect. If that is correct, make sure your label isn't somehow being obstructed by another control. You can do a view source on the page to see if and where the label is being rendered.
 
I think I got it figured out. I had the label inside the createuserwizard control, and though it DID show for my custom first step (where I ask for the user address and stuff), it did NOT show up for the actual "enter username/password" step. So I moved the label outside of the control and now it works. Silly mistake, but thanks. :)

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top