Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
For the netwo<code>rkcredential, any directive other than System.Net.Mail is required????
In the button click I did coding . but Iam getting an error ""The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated ""
coding is like this

protected void Button1_Click(object sender, EventArgs e)
    {
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.To.Add(TextBox1.Text);
        mail.From = new System.Net.Mail.MailAddress("from");
        mail.Body = "Your new password is xxxx";
        mail.Subject = "New Password";
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("localhost");
        try
        {
            smtp.Send(mail);
            
            Response.Write("The mail has been sent to ");
            Response.Write(mail.To);
        }
        catch (System.Exception ex)
        {
            Response.Write(ex.Message);
        } 
    }
I have created one login page. In that there is an option for reset password. How can I reset the password. I need to do the codeing as, when the user click the reset button a new password should be send to his mail. How can I do this. From where I have to start. pls help.
Posted
Updated 17-Oct-11 22:27pm
v4
Comments
CodingLover 13-Oct-11 0:51am    
Reset password sense, there are two things. Change password and the recover forget password. Which one you are looking for?
lll1234 13-Oct-11 5:23am    
In the reset button click i did coding like this. but it is not working


MailMessage TravelMailMessage = new MailMessage();

TravelMailMessage.BodyFormat = MailFormat.Html;

TravelMailMessage.To="to mail id";
TravelMailMessage.From="from mail id";
TravelMailMessage.Body="New Password";
TravelMailMessage.Subject="Your new Password is xxxx";
SmtpMail.SmtpServer="server";

First of all you need to verify the use authentication using any security question answered by user at registration time and then generate some random code
update database with that code and then send mail to the user.

to send email check this.
How to send email through asp.net[^]
 
Share this answer
 
Comments
Anuja Pawar Indore 13-Oct-11 2:25am    
My 5
P.Salini 13-Oct-11 2:29am    
Thanks anuja
you should need to update password in your database also and send a mail that specifies new password.
to send mail use
C#
public static Boolean SendingMail(string From, string To, string Subject, string Body)
   {

           try
           {
               MailMessage m = new MailMessage("uid", To);
               m.Subject = Subject;
               m.Body = Body;
               m.IsBodyHtml = true;
               m.From = new MailAddress(From);

               m.To.Add(new MailAddress(To));
               SmtpClient smtp = new SmtpClient();
               smtp.Host = "mail.google.com";

               NetworkCredential authinfo = new NetworkCredential("uid", "password");
               smtp.UseDefaultCredentials = false;
               smtp.Credentials = authinfo;
               smtp.Send(m);
               return true;




           }
           catch (Exception ex)
           {
               return false;
           }
       }
 
Share this answer
 
First of all you need to verify the use authentication using any security question answered by user at registration time and then reset his/her password

OR

You can directly send a email of new password to his/her mail id given on registration time.

For resetting password you can just fire a UPDATE query to you db and set new password on the basis of the user criteria matched on above any condition

For Reset Password, you can reset it with user's birth date or you can also genrate random word using coding to reset the password.



For Sending Email Please see this link it will help full to you..
How to send A E-Mail From Your ASP.NET web Application...?[^]
 
Share this answer
 
First of all you need to verify the security question and answer from user and pass the question,answer to the following stored procedure. It will update random password and returns password, which you can sends to customer in email.

CREATE PROCEDURE [dbo].[prc_UpdatePassword]
(
	@secretquestion varchar(100)='',
	@secretanswer varchar(100)='',
	@ReturnVal varchar(10) out
)
as
begin
if exists (select * from tbl_MUSR where secretquestion=@secretquestion and secretanswer=@secretanswer)
Begin
			--Generate Random Password
			Declare @Length int
			DECLARE @strPassword varchar(32)
			DECLARE @counter smallint
			DECLARE @RandomNumber float
			DECLARE @RandomNumberInt tinyint
			DECLARE @CurrentCharacter varchar(1)
			DECLARE @ValidCharacters varchar(255)
			SET @ValidCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+&$'
			DECLARE @ValidCharactersLength int
			
			declare @iLicence int
			declare @iInsured varchar(10)
			
			SET @ValidCharactersLength = len(@ValidCharacters)
			SET @CurrentCharacter = ''
			SET @RandomNumber = 0
			SET @RandomNumberInt = 0
			SET @strPassword = ''

			SET NOCOUNT ON

			SET @counter = 1
			set @Length=8
			WHILE @counter < (@Length + 1)
			BEGIN
					SET @RandomNumber = Rand()
					SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength - 1) * @RandomNumber + 1))
					SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters, @RandomNumberInt, 1)
					SET @counter = @counter + 1
					SET @strPassword = @strPassword + @CurrentCharacter
			END
			update tbl_MUSR set Password=@strPassword where secretquestion=@secretquestion and secretanswer=@secretanswer
			set @ReturnVal=@strPassword
end
else
	set @ReturnVal='Not Found'
end
 
Share this answer
 
Hi lll123,

When we are sending mails using System.Net.mail we must need to provide credential like
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.google.com";
NetworkCredential authinfo = new NetworkCredential("uid", "password");
smtp.UseDefaultCredentials = false;
smtp.Credentials = authinfo;


this will solve your problem
 
Share this answer
 
Comments
lll1234 18-Oct-11 2:48am    
hi
For this network credential is any other compiler directive required????
[no name] 19-Oct-11 4:44am    
for this you need to import system.net
lll1234 20-Oct-11 4:48am    
any other compiler directive ???
[no name] 20-Oct-11 6:53am    
no any other required :)

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