removed singleton pattern and renamed class
authorFelix Schumacher <felix.schumacher@internetallee.de>
Tue, 24 Aug 2010 18:32:00 +0000 (20:32 +0200)
committerFelix Schumacher <felix.schumacher@internetallee.de>
Tue, 24 Aug 2010 18:32:00 +0000 (20:32 +0200)
src/org/mcb/services/loginmanager.java
src/org/mcb/services/passwordservices.java [deleted file]
src/org/mcb/services/udac.java

index 63a3e43..d7745d1 100644 (file)
@@ -15,6 +15,15 @@ import javax.servlet.http.HttpSession;
 public class loginmanager extends HttpServlet {
 
        private static final long serialVersionUID = 1L;
+       private transient PasswordService passwordservice;
+       private udac udac;
+       
+       @Override
+       public void init() throws ServletException {
+               super.init();
+               this.passwordservice = new PasswordService();
+               this.udac = new udac(passwordservice);
+       }
 
        /**
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
diff --git a/src/org/mcb/services/passwordservices.java b/src/org/mcb/services/passwordservices.java
deleted file mode 100644 (file)
index aa8f273..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.mcb.services;
-
-/**
- * 
- * @author yawar.saeed
- */
-
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import sun.misc.BASE64Encoder;
-
-public final class passwordservices {
-       private static passwordservices instance = new passwordservices();
-
-       private passwordservices() {
-       }
-
-       public synchronized String encrypt(String plaintext) throws Exception {
-               MessageDigest md = null;
-               try {
-                       md = MessageDigest.getInstance("SHA"); // step 2
-               } catch (NoSuchAlgorithmException e) {
-                       throw new Exception(e.getMessage());
-               }
-               try {
-                       md.update(plaintext.getBytes("UTF-8")); // step 3
-               } catch (UnsupportedEncodingException e) {
-                       throw new Exception(e.getMessage());
-               }
-               byte raw[] = md.digest(); // step 4
-               String hash = (new BASE64Encoder()).encode(raw); // step 5
-               return hash; // step 6
-       }
-
-       public static synchronized passwordservices getInstance() // step 1
-       {
-               return instance;
-       }
-}
index e36dd35..fd79b9d 100644 (file)
@@ -10,7 +10,13 @@ import java.sql.Statement;
 
 public class udac {
 
-       public static userbean login(userbean user) {
+       private PasswordService passwordservice;
+
+       public udac(PasswordService passwordservice) {
+               this.passwordservice = passwordservice;
+       }
+
+       public userbean login(userbean user) {
                // preparing some objects for connection
                Connection currentCon = null;
                ResultSet rs = null;
@@ -25,7 +31,7 @@ public class udac {
                String last_login = null;
                String role_desc = null;
                try {
-                       epass = passwordservices.getInstance().encrypt(password);
+                       epass = this.passwordservice.encrypt(password);
                } catch (Exception e) {
                        System.out.println(e);
                }