Do you receive the Programmer's Heaven newsletter? If not, why not subscribe?

View java\java\bin\manoveg\server\CheckClient.java

networking authentication program 1.0

Submitted By: manoveg
Rating: (Not rated) (Rate It)


package server;

import java.awt.*;
import java.util.*;
import java.sql.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class CheckClient
{

 public static Connection dbConnection1() throws SQLException , IOException
 {
  Properties props=new Properties();
  FileInputStream in=new FileInputStream("D:/java/java/bin/manoveg/server/database.properties");
  props.load(in);
  in.close();

  String drivers=props.getProperty("jdbc.drivers");
  if(drivers!=null)
  System.setProperty("jdbc.drivers",drivers);
  String url=props.getProperty("jdbc.url");
  String username=props.getProperty("jdbc.username");
  String password=props.getProperty("jdbc.password");
  return DriverManager.getConnection(url,username,password);

  }
 
 public String check(String USpass)
 {
  String rstring="";

 String temp=USpass;
 String user="";
 String search="$";
 String pass="";
 char upass[] = new char[50];
 upass = USpass.toCharArray();
 int i,counter,j;
 i=temp.indexOf(search);
 user=temp.substring(0,i);
 pass=temp.substring(i+1,temp.length());
 System.out.println(""+user+" "+pass);
 String dmuser="";
 String dmpwd="";
 boolean flag=false;
 
 
  try
 {
  Connection conn = dbConnection1();
  Statement stat1=conn.createStatement();
  ResultSet rs1 = stat1.executeQuery("SELECT username,password FROM mylogin");
 
  while(rs1.next())
   {
    dmuser=rs1.getString("username");
    dmpwd=rs1.getString("password");
    if(user.equals(dmuser))
    {
     if(pass.equals(dmpwd))
     {
      flag=true;
      break;
     }
    }
   }
 
 if(flag==false)
     {
      throw new SQLException();
     }

    if(flag==true)
    {
      rstring="Login successful";

     }

   conn.close();
   
 }
   catch (SQLException ex)
   {
     rstring="Login Failed";
   }
   catch (IOException ex)
   {
    rstring="Login Failed due to read write error"+ex;
   }
 
  return rstring;

 }


 public String checkPwd(String USpass)
 {
  String rstring="";

 String temp=USpass;
 String user="";
 String search="$";
 String pass="";
 String newpass="";
 char upass[] = new char[100];
 upass = USpass.toCharArray();
 int i,counter,j;
 i=temp.indexOf(search);
        j=temp.lastIndexOf(search);
 user=temp.substring(1,i);
 pass=temp.substring(i+1,j);
  newpass=temp.substring(j+1,temp.length());
 System.out.println(""+user+" "+pass+" "+newpass);
 String dmuser="";
 String dmpwd="";
 boolean flag=false;
 
 
  try
 {
  Connection conn = dbConnection1();
  Statement stat1=conn.createStatement();
  ResultSet rs1 = stat1.executeQuery("SELECT username,password FROM mylogin");
 
  while(rs1.next())
   {
    dmuser=rs1.getString("username");
    dmpwd=rs1.getString("password");
    if(user.equals(dmuser))
    {
     if(pass.equals(dmpwd))
     {
      flag=true;
      break;
     }
    }
   }
 
 if(flag==false)
     {
      throw new SQLException();
     }

    if(flag==true)
    {
      rstring="PWd successful";
      stat1.executeUpdate("UPDATE mylogin SET password='"+newpass+"' where username='"+user+"'");
     }

     

   conn.close();
   
 }
   catch (SQLException ex)
   {
     rstring="PWD Failed";
   }
   catch (IOException ex)
   {
    rstring="Login Failed due to read write error";
   }
 
  return rstring;

 }

}

corner
© 1996-2008. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.