Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1946
  • Last Modified:

Visual Studio Express 2013 for Web: Registering a new account using email instead of username

Hi, I created a new asp.net web forms site in Visual Studio Express 2013 for Web, and the default Register account page created by the software is asking the user to enter a username, password and confirm password.

How do I edit this form to ask the user to enter email instead of username?

I want the "email" textfield to be both required and validated as email, so I added a "RegularExpressionValidator" below the "RequiredFieldValidator" as follows...

<asp:TextBox runat="server" ID="UserName" CssClass="form-control" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="The email field is required." />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="Please enter a valid email." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />

Open in new window


Is this the correct way? Because the "Please enter a valid email." error message is  appearing a bit too the right, as in the attached screenshot "email.jpg".

Second question, still on the register account page, even after entering a valid looking email, the two password fields and pressing "Register", there is an error message that says "User name 2@2.com is invalid, can only contain letters or digits".

In "Register.aspx.vb", there is the following code...

Public Partial Class Account_Register
    Inherits Page
    Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
        Dim manager = New UserManager()
        Dim user = New ApplicationUser() With {.UserName = userName.Text}
        Dim result = manager.Create(user, Password.Text)
        If result.Succeeded Then
            IdentityHelper.SignIn(manager, user, isPersistent:=False)
            IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
        Else
            ErrorMessage.Text = result.Errors.FirstOrDefault()
        End If
    End Sub
End Class

Open in new window


The "manager.Create" function is under "UserManagerExtensions" under "Microsoft.AspNet.Identity.Core" under "Object Browser".

What do I need to do so that I can register a new account using email address successfully?
Thanks.
email.jpg
0
killdurst
Asked:
killdurst
  • 3
  • 2
2 Solutions
 
Paul JacksonCommented:
For the first question you just need to set the display property for both validators to be dynamic, then it won't reserve the space for the validators unless it is needed (i.e when an error occurs) :

<asp:TextBox runat="server" ID="UserName" CssClass="form-control" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="The email field is required."  Display="Dynamic"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="Please enter a valid email." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic"/>

Open in new window

0
 
killdurstAuthor Commented:
Cool, thanks!
Ok, now hoping for an answer to the second question... :)
0
 
Paul JacksonCommented:
Seems that allowing users to register with emails is not supported out of the box with ASP.Net Identity but there is a community template that allows it to be done see:

http://www.asp.net/single-page-application/overview/templates/backbonejs-template
0
 
killdurstAuthor Commented:
Seems that with backbone, we have to use "project" and "C#" instead of "web site" and "visual basic". And I encountered an error when creating a new backbone project. See attached screenshot.

Anyway, as an alternative, can the "Register" page be updated to include an "email" field?
What are the files that needs to be updated so the the email field is also stored in the database?

Basically, I would like to create an asp.net site using visual basic that would also allow users to also reset password and stuff. If there are any free templates or easy to use cms/frameworks out there, do let me know. Thanks.
error.jpg
0
 
killdurstAuthor Commented:
Just thought of a workaround for this...

I am thinking of converting the email that the user inputs on the register page into a hash string or just numbers just so that the account can be registered.
But the converted string must only have letters and digits, no "+", "/", "=", etc.

Of course, the hashed string must be able to be restored as the email address so that I can display it on the header and stuff.

What are the ways I can convert the email into a string made up of just letters and digits?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now