Solved

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

Posted on 2013-12-02
5
1,877 Views
Last Modified: 2014-01-13
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
Comment
Question by:killdurst
  • 3
  • 2
5 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 500 total points
ID: 39691656
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
 
LVL 1

Author Comment

by:killdurst
ID: 39691690
Cool, thanks!
Ok, now hoping for an answer to the second question... :)
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39691696
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
 
LVL 1

Author Comment

by:killdurst
ID: 39691742
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
 
LVL 1

Author Comment

by:killdurst
ID: 39692052
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error on the asp.net page 1 32
C# Offline Apllication 5 48
Error on Add method 1 36
.Net Web Site IIS Web.Config Content-Security-Policy 1 34
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now