User Registration verification Link

Karthikreddy
Posted by Karthikreddy under ASP.NET category on | Points: 40 | Views : 1017
want to avoid the fake Registration to our web site ? place fallowing code under registration page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// GetUniqueReferalid(12);
}
public static string GetUniqueReferalid(int length)
{
char[] chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
string password = string.Empty;
Random random = new Random();

for (int i = 0; i < length; i++)
{
int x = random.Next(1, chars.Length);

if (!password.Contains(chars.GetValue(x).ToString()))
password += chars.GetValue(x);
else
i--;
}

return password;

}
public static void sendEmail(string Emailid,string uid)
{
uid = GetUniqueReferalid(12);
MailMessage msg = new MailMessage();
// msg.From = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["FROMEMAIL"].ToString());
msg.From = new MailAddress("XXXXXX@XXXXXXXXX.com");
string _toId = Emailid.ToString();
msg.To.Add(new MailAddress(_toId));
msg.Subject = "Administrator";
StringBuilder sb = new StringBuilder();
msg.IsBodyHtml = true;
sb.Append("Administrator");
sb.Append("<br>Thanks for Register with us Clik on the verification link to continue registration <br>");
sb.Append("<br>");
sb.Append("<a href='http://www.google.co.in/webhp?source=" + uid + "'>http://www.google.co.in/webhp?source=" + uid + "</a>");
msg.Body = sb.ToString();
SmtpClient smtp = new SmtpClient("localhost",25);

smtp.Host="smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("your_mailid@domain.com","your_password");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
//smtp.UseDefaultCredentials = true;
try
{
smtp.Send(msg);
}
catch (Exception ex)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string email = TextBox1.Text;
sendEmail(email,"");
}
}

Comments or Responses

Login to post response