使用C#进行电子邮件确认 [英] E-mail confirmation using c#

查看:271
本文介绍了使用C#进行电子邮件确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发应用程序;特别是在我的用户注册模块上,其中用户将输入用户ID,电子邮件,密码并确认密码.

注册后我会向他们发送电子邮件,其中包括他们的LoginDetails
(我已经完成了此操作)

我怎么不知道如何确认他们的电子邮件是否合法.
例如,当我们注册Facebook时,它将向我们发送一封电子邮件,其中包含用于确认我们的电子邮件地址的链接.我该怎么办?

我真的不知道如何执行此操作.

I am currently developing an application; specifically on my registration module for users wherein they would input their UserID, E-mail, Password, and confirm password.

I am knowledgeable in sending E-mails to them after registration which includes their LoginDetails
(I was done with this already)

How ever I have no Idea on how to confirm if their email is legit.
For example, when we sign-up for facebook, it will send us an e-mail containing a link to confirm our email address. how can I do this?

I literally have no idea on how to do this.

推荐答案

您好,
这很简单.
尝试生成Unqiue随机数或String或两者的组合,并将其存储在某处一段时间(例如24小时).现在,通过电子邮件发送此生成的代码并要求确认,一旦他/她也使用该代码登录到您的系统,则该用户已通过身份验证,或者他/她有可能在两天后再出现,然后再次询问用户重新生成代码并获得确认邮件.

例如,如果您只想生成随机数
Hello,
It''s a pretty simple.
Try to generate Unqiue Random Number or String or maybe combination of both and store it somewhere for some time let''s say 24 hrs. Now send this generated code via email and ask for confirmation, as soon as he/she gets logged into your system using that code as well, user is authenticated or it might be possible that he/she comes after 2 days, then again ask user to re-generate the code and get the confirmation mail.

For example, if you want tot generate random numbers only,
private int RandomNumber(int min, int max)
{
    Random random = new Random();
    return random.Next(min, max);
}


现在您可能还想生成随机字符串.


Now you may also want to generate random strings.

private string RandomString(int size, bool lowerCase)
{
    StringBuilder builder = new StringBuilder();
    Random random = new Random();
    char ch ;
    for(int i=0; i<size; i++)
    {
        ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
        builder.Append(ch); 
    }
        if(lowerCase)
        return builder.ToString().ToLower();
    return builder.ToString();
}


您甚至可以结合使用两种方法-RandomNumber和RandomString来生成随机字符串和数字的c 组合.例如,以下代码生成长度为10的密码,其中前4个字母小写,后4个字母数字,后2个字母为大写.


You can even combine the two methods - RandomNumber and RandomString to generate a combination of random string and numbers. For example, the following code generates a password of length 10 with first 4 letters lowercase, next 4 letters numbers, and last 2 letters as uppercase.

public string GetPassword()
{
    StringBuilder builder = new StringBuilder();
    builder.Append(RandomString(4, true));
    builder.Append(RandomNumber(1000, 9999));
    builder.Append(RandomString(2, false));
    return builder.ToString();
}



您可能会在此处 [此处 [ ^ ].

希望你有主意. :)

-KR



You may find this random string generator here[^] and here[^].

Hope you got the idea. :)

-KR


检查本文:单击此处


该想法可能是使用数字签名.请参阅:
http://en.wikipedia.org/wiki/Public-key_cryptography [ http://en.wikipedia.org/wiki/Digital_signature [ http://msdn.microsoft.com/zh-cn/library/system.security.cryptography.asymmetricalgorithm%28v=vs.110%29.aspx [
The idea could be using digital signature. Please see:
http://en.wikipedia.org/wiki/Public-key_cryptography[^],
http://en.wikipedia.org/wiki/Digital_signature[^].

In .NET FCL, everything is done for you: http://msdn.microsoft.com/en-us/library/system.security.cryptography.asymmetricalgorithm%28v=vs.110%29.aspx[^].

—SA


这篇关于使用C#进行电子邮件确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆