• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How To Find out the Password from the database

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i am working on this situation :
Have to find out the password from the databse knowing the e-mail address of the user. Same this as it is used in This forum in case any one forget the password. I can submit the query to the database and can retrive the password from the databse. Now to prevent the missuse and to provide security i have to send this password to the found e-mail. So how can i do this automatically. How can i send the e-mail to the user automatically using the input e-mail address...compared to the database e-mail address.
Can any one help me with some code, pls.
Thnnks,
Regards
Raj.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Querying the database part is as per the normal procedure. Using the select query you can find out whether the record exist or not and then get the password from the database .Now the problem is how to send it to the user's email account .
You can do this in two ways
1) using the SmtpClient
2) using java mail package.
if u are using the SmtpClient the cose is as follows .
import sum.net.smtp.*;
Inthe servcice method you can write the following Code
SmtpClient smClient=new SmtpClient("MmailHostName");
//mailHostName can be like 'mail.webveda.com'
smClient.from("yourEmailAddress");
smClient.to("recipient email address");
PrintStream ps=smClient.startMessage();
ps.println("from "+ "yourEmailAddress");
ps.println("from "+ "recipient email address");
ps.println("write the subject that u wanna writeeg ur
password is xyz12344 or something ");
smClient.closeServer();
To find out whether the mail has been send or not put the entire code in try block .If the mail cannot be send because of some problem an exception will raise.
the second method is using the javax mail package u can send the mail .
------------------
Sandeep Jain
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,

Here is the code that can be useful to you.
Just Imagine that my database name is email and the table name is passwd. You just prepare an html file asking the user to enter his/her email address.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import sun.net.smtp.*;
public class authenticate extends HttpServlet
{
private Connection con;
private Statement stat;
private SmtpClient client;
public void init(ServletConfig config) throws ServletException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:email");
client=new SmtpClient("MAIL_HOST")//replace
//MAIL_HOST with proper host.
}
catch(ClassNotFoundException cnfe)
{
getServletContext().log(cnfe,"Could not found class");
}
}

public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String uaddr=req.getParameter("uaddress");//uaddress=user
//email address
String sql="select password from passwd";//password is
//field name and passwd is table name.
try
{
ResultSet r=stat.executeQuery(sql);
if(r!=null)
{
r.next();
String p=r.getString(1);
if(p!=null)
{
client.from("team@urname.com");
client.to(uaddr);
PrintStream ps=client.startMessage();
ps.println("From: "+"team@urname.com");
ps.println("To: "+uaddr);
ps.println("Subject: Your Password");
ps.println("Dear user here is ur password "+p);
client.closeServer();
}
}
}
catch(SQLException sqe)
{
getServletContext().log(sqe,sqe.toString());
}
catch(Exception e)
{
getServletContext().log(e,"Exception occured");
}
}
public void destroy()
{
try
{
if(con!=null)
{
con=null;
}
}
catch(SQLException sqe)
{
getServletContext().log(sqe,sqe.toString());
}
}
}
Raj i dint tested this code, but i am sure that it works fine, if anything goes wrong please intimate me.
I hope this code will be useful to you.
Loke.
[This message has been edited by lokesh reddy (edited October 27, 2000).]
 
Rajpal Kandhari
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sandeep & Lokesh,
Thanks for you're help and code. Lokesh i tried to compile you're code. But i am having pb with the line
client = new SmtpClient("Mail_Host");
//you have asked me to enter a mail host name.
I am working on win98 machine and have Outlook Express installed. Well this work?
I want to run the code on my system and see if this thing is working or not. I don't have a net connection on my system, I surf from the cafe. Do i need a net connection to try out the code.? I am confused as how to make it work. I made the database and entered values in them. But i am getting a Null Pointer Exception on the above mention line. Pls advice me as what to do.
Regards,
Raj.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the intention in the code example is that you replace "Mail_Host" with the name or IP address of the SMTP server you are trying to send mail with. Look at the properties in Outlook Express and see what the SMTP mail host is set to, then put the same in your code.
 
lokesh reddy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,
You please replace the "MAIL_HOST" with proper smtp server ip address or host name. If you want to try, you can check by replacing the "MAIL HOST" with the following address.
1) mail.sigmaonline.net
2) mail.webveda.com
Raj, you need to have net connection to make this program execute. But, even in a cyber cafe also you can run it. If it doesn't work there, then i think that you are behind a proxy server. If u r really behind a proxy server, then please add these two lines of code in the init method.
Properties prop=System.getProperties();
prop.put("http.proxyHost","Server Host Name") //Replace Server
//Host Name with your Server IP Address.
prop.put("http.proxyPort","Server Port") //Replace Server Port
//with the Port Number of your server.
For ur convenience i am giving an example here.
***********************************************
Properties prop=System.getProperties();
prop.put("http.proxyHost","197.100.0.1");
prop.put("http.proxyPort","80");
***********************************************
Remember to add these two line in the begining of the init method.
Loke.
 
Rajpal Kandhari
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Frank and Lokesh,
Thanks for you're help.

Lokesh I will try to run the code at the cafe but first i have to install necessary software their. It can take some time. I will come back to you when it is done. Thanks.

Regards,
Raj.
 
reply
    Bookmark Topic Watch Topic
  • New Topic