Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hello Sir,

I want to send an email with the confirmation code when the user first registers to the site. How to attach random number with email? How to compare it when user enters sent code???plz reply....i m new to asp.net
Posted
Comments
[no name] 11-Oct-12 11:18am    
What is wrong with including your random number in the body of the email?
Sergey Alexandrovich Kryukov 11-Oct-12 11:55am    
What is "attach" in this content? You simply send the value in the e-mail, in text form. By the way, I feel that your schema might be unsafe, a subject of a fake impersonation.
--SA

1 solution

I wouldn't use an random number: I use a Guid instead:
C#
Guid g = Guid.NewGuid();
SaveToDatabaseAsActivationCode(g);
SendToEmailWithRegistratcionLetter(g.ToString());




"Hello Sir,
Plz explain me the above code, what is the work of Guid and what is the use of these lines..

SaveToDatabaseAsActivationCode(g);
SendToEmailWithRegistratcionLetter(g.ToString());"


A Guid is basically a 128 bit number, which is generated by the system on demand. It is called a Globally Unique IDentifier - which is where the "GUID" bit comes in - and it is commonly used for database ID fields, because the chances of you generating two identical GUID values in your application are higher than the chances of you winning the lottery.

This weekend.
And next weekend, and every single weekend until the end of your life.
The odds are absolutely staggering!

I use them in registration to provide a unique code I can tie up with a user ID and confirm an email address: Send the user an email to his registered address, with teh body as HTML, with a link back to a "Registration complete" page using a query string containing the userID and the GUID. A quick check in the DB that we are waiting for a link from that userID with that GUID, and all if fine.

The two method calls are just examples for you: the names are supposed to indicate the two actions you would need to do with the GUIDwhen you have generated it, and to show that Guid supports the ToString method to produce a "human readable" version.
 
Share this answer
 
v2
Comments
Member 9505361 11-Oct-12 12:17pm    
plz explain me the above code Sir..
Member 9505361 11-Oct-12 12:20pm    
Hello Sir,
Plz explain me the above code, what is the work of Guid and what is the use of these lines..

SaveToDatabaseAsActivationCode(g);
SendToEmailWithRegistratcionLetter(g.ToString());
OriginalGriff 11-Oct-12 14:07pm    
Answer updated.
Member 9505361 11-Oct-12 22:28pm    
Thank so much Sir,
I got idea about GUID, I want to understand what is the use of these methods,
SaveToDatabaseAsActivationCode()
SendToEmailWithRegistratcionLetter()
OriginalGriff 12-Oct-12 3:32am    
Read the last paragraph of my answer!
They are examples of what you have to do - it is up to you to fill in the methods themselves as I do not know how your code works at present. :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900