Invent Registration Confirmation Procedure

0

The idea is to make the registration, send the user an email containing a link, where he can confirm the registration and only release the permission to log in. Just to have a little more security and prevent any email from being registered. How to do?

    
asked by anonymous 01.10.2014 / 04:41

1 answer

2

Just to have a little more security and prevent any email from being registered. How to do?

Using an attribute called [EmailAddress] in your e-mail field. It validates perfectly if the string is a valid email or not.

[EmailAddress]
public String MeuEnderecoDeEmail { get; set; }

The idea is to make the registration, send the user an email containing a link, where he can confirm the registration and only release the permission to log in.

To do this, you need to create a pattern for confirmation. For example, a token in base64 . Here are two methods to generate a token:

public static string Base64Encode(string minhaString) {
    var bytes = System.Text.Encoding.UTF8.GetBytes(minhaString);
    return System.Convert.ToBase64String(bytes);
}

public static string Base64Decode(string stringCriptografada) {
    var bytes = System.Convert.FromBase64String(stringCriptografada);
    return System.Text.Encoding.UTF8.GetString(bytes);
}

Make a method that generates a token like this (the input string you define) and save it to your Model .

To set up an email, you can use a service like SendGrid that already has a good solution ready to use. Here they teach you how to assemble and send an email through your application .

    
01.10.2014 / 06:45