3 |
4 |
5 |
6 |
7 | Data Owner Home
8 |
10 |
11 |
12 |
13 |
14 |
15 |
17 |
Data Owner Home Page
18 |
19 |
20 | <%@include file="/html/dataowner_menu.html"%>
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/fks/WebContent/docupload.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 |
4 |
5 |
6 |
7 | Upload The Documents
8 |
10 |
11 |
12 |
13 |
35 |
36 |
37 | <%
38 | HttpSession hs = request.getSession(false);
39 | String uid = (String) hs.getAttribute("userid");
40 | %>
41 |
43 |
Upload Documents
44 |
45 |
46 | <%@include file="/html/dataowner_menu.html"%>
47 |
48 |
49 |
83 | <%
84 | String file_name=(String)request.getParameter("filename");
85 | if(file_name!=null){
86 | out.println(file_name+" File uploaded successfuly");
87 | }
88 | %>
89 |
90 |
91 |
--------------------------------------------------------------------------------
/fks/WebContent/doedit.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@page import="java.sql.*,fks.dbtasks.*,fks.servlet.*" %>
4 |
5 |
6 |
7 |
8 | Edit Profile
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
Edit Profile
20 |
21 |
22 | <%@include file="/html/dataowner_menu.html"%>
23 |
24 |
66 |
67 |
--------------------------------------------------------------------------------
/fks/WebContent/fonts/Aulyars Italic.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/Aulyars Italic.otf
--------------------------------------------------------------------------------
/fks/WebContent/fonts/Aulyars.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/Aulyars.otf
--------------------------------------------------------------------------------
/fks/WebContent/fonts/Punktype.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/Punktype.ttf
--------------------------------------------------------------------------------
/fks/WebContent/fonts/atomic STARGAZE.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/atomic STARGAZE.ttf
--------------------------------------------------------------------------------
/fks/WebContent/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/fks/WebContent/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/fks/WebContent/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/fks/WebContent/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/fks/WebContent/html/cloud_menu.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Cloud Menu
6 |
7 |
9 |
10 |
11 |
12 |
13 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/fks/WebContent/html/dataowner_menu.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Data Owner Menu
6 |
11 |
12 |
13 |
23 |
24 |
--------------------------------------------------------------------------------
/fks/WebContent/html/user_menu.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | User Menu
6 |
7 |
9 |
10 |
11 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/fks/WebContent/idcheck.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@page import="java.sql.*,fks.dbtasks.*,java.io.*" %>
4 |
5 |
6 |
7 |
8 | Check ID
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | <%
18 | response.setContentType("text/html");
19 | PrintWriter o=response.getWriter();
20 | String id=request.getParameter("recid");
21 | System.out.println(id);
22 | String str1="select * from logininfo where userid=?";
23 | ResultSet rs=CrudOperation.fetchData(str1, id);
24 | if(rs.next())
25 | {
26 | out.println("ID already taken
");
27 | }
28 | else
29 | {
30 | out.println("ID available
");
31 | }
32 | rs.close();%>
33 |
34 |
--------------------------------------------------------------------------------
/fks/WebContent/images/PFL020118.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/PFL020118.jpg
--------------------------------------------------------------------------------
/fks/WebContent/images/cldcmp.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/cldcmp.jpg
--------------------------------------------------------------------------------
/fks/WebContent/images/cldlgn.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/cldlgn.jpg
--------------------------------------------------------------------------------
/fks/WebContent/images/cmp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/cmp.png
--------------------------------------------------------------------------------
/fks/WebContent/images/docpat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/docpat.jpg
--------------------------------------------------------------------------------
/fks/WebContent/images/i2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/i2.jpg
--------------------------------------------------------------------------------
/fks/WebContent/images/i3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/i3.jpg
--------------------------------------------------------------------------------
/fks/WebContent/images/join-background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohitv0909/Fuzzy-Keyword-Search/2a470db84993eaec2edd991a72b16ff7507ef972/fks/WebContent/images/join-background.jpg
--------------------------------------------------------------------------------
/fks/WebContent/js/validation.js:
--------------------------------------------------------------------------------
1 | function checkEmpty(data)
2 | {
3 | if (data.length == 0)
4 | return false
5 | else
6 | return true
7 | }
8 |
9 | function checkLength(data)
10 | {
11 | if (data.length<8 )
12 | return false
13 | else
14 | return true
15 | }
16 |
17 | function checkPhone(data)
18 | {
19 | if (data.length==10)
20 | return true
21 | else
22 | return false
23 | }
24 |
--------------------------------------------------------------------------------
/fks/WebContent/login.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 |
4 |
5 |
6 |
7 | Login
8 |
10 |
11 |
12 |
13 |
43 |
44 |
45 | <%
46 | String ms = (String) request.getAttribute("msg");
47 | %>
48 | Cloud Portal
49 |
50 |
51 |
59 |
60 |
94 |
95 |
--------------------------------------------------------------------------------
/fks/WebContent/message.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
5 |
6 |
7 |
8 | Upload Result
9 |
10 |
11 |
12 | ${message}
13 |
14 |
15 |
--------------------------------------------------------------------------------
/fks/WebContent/reg.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 |
4 |
5 |
6 |
7 | Registration
8 |
10 |
11 |
12 |
13 |
86 |
94 |
95 |
96 | REGISTRATION
97 |
172 |
173 |
--------------------------------------------------------------------------------
/fks/WebContent/search.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@page import="java.sql.*,fks.dbtasks.CrudOperation,java.io.*,fks.servlet.*" %>
4 |
5 |
6 |
7 |
8 | User Home
9 |
11 |
12 |
13 |
14 |
15 |
16 |
18 |
Search Files
19 |
20 |
21 | <%@include file="/html/user_menu.html"%>
22 |
23 |
24 | <%-- <%
25 | HttpSession hs=request.getSession(false);
26 | String uid=(String)hs.getAttribute("userid");
27 | String strsql="select * from auth where userid=?";
28 | ResultSet rs=CrudOperation.fetchData(strsql,uid);
29 | if(rs.getString("request").equalsIgnoreCase("no"))
30 | {
31 | %>
32 |
38 | <%
39 | }
40 | else
41 | {
42 | %> --%>
43 |
53 | <%-- <%
54 | }
55 | rs.close();
56 | %> --%>
57 |
58 |
59 |
--------------------------------------------------------------------------------
/fks/WebContent/uedit.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@page import="java.sql.*,fks.dbtasks.*,fks.servlet.*" %>
4 |
5 |
6 |
7 |
8 | Edit Profile
9 |
11 |
12 |
13 |
14 |
15 |
16 |
18 |
Edit Profile
19 |
20 |
21 | <%@include file="/html/user_menu.html"%>
22 |
23 |
24 |
59 | <% String message = (String)request.getAttribute("msg");%>
60 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/fks/WebContent/user_home.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 |
4 |
5 |
6 |
7 | User Home
8 |
10 |
11 |
12 |
13 |
14 |
15 |
17 |
User Home Page
18 |
19 |
20 | <%@include file="/html/user_menu.html"%>
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/fks/WebContent/viewsearch.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@page import="java.sql.*,fks.dbtasks.*,java.io.*,fks.servlet.*" %>
4 |
5 |
6 |
7 |
8 | Check ID
9 |
11 |
12 |
13 |
14 |
28 |
29 |
30 |
32 |
View Search Result(s)
33 |
34 |
35 | <%@include file="/html/user_menu.html"%>
36 |
37 |
90 |
91 |
--------------------------------------------------------------------------------
/fks/WebContent/viewupfiles.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@page import="java.sql.*,fks.dbtasks.*,fks.servlet.*" %>
4 |
5 |
6 |
7 |
8 | View Uploaded Documents
9 |
11 |
12 |
13 |
14 |
28 |
29 |
30 |
31 |
33 |
View Uploaded Documents
34 |
35 |
36 | <%@include file="/html/dataowner_menu.html"%>
37 |
38 |
39 |
40 | File Name |
41 | Encrypted File Name |
42 | File Path |
43 | Encrypted File Path |
44 |
45 | <%
46 | HttpSession hs=request.getSession(false);
47 | String uid=(String)hs.getAttribute("userid");
48 | String key=(String)hs.getAttribute("userkey");
49 | String strsql="select * from document where userid=?";
50 | ResultSet rs=CrudOperation.fetchData(strsql,uid);
51 | while(rs.next())
52 | {
53 | %>
54 |
55 | <%=AES.decrypt(rs.getString("fname"), key) %> |
56 | <%=rs.getString("fname") %> |
57 | <%=AES.decrypt(rs.getString("fpath"), key) %> |
58 | <%=rs.getString("fpath") %> |
59 |
60 | <%
61 | }
62 | rs.close();%>
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/fks/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/fks/src/fks/dbinfo/database.properties:
--------------------------------------------------------------------------------
1 | app.dbuserid=root
2 | app.dbuserpass=root
3 | app.url=jdbc:mysql://localhost:3306/fks
4 | app.tagline=Safe and secure cloud.
--------------------------------------------------------------------------------
/fks/src/fks/dbtasks/CrudOperation.java:
--------------------------------------------------------------------------------
1 | package fks.dbtasks;
2 | import java.sql.Connection;
3 | import java.sql.DriverManager;
4 | import java.sql.PreparedStatement;
5 | import java.sql.ResultSet;
6 | import java.sql.SQLException;
7 | import java.util.ResourceBundle;
8 | public class CrudOperation
9 | {
10 | private static Connection cn;
11 | private static PreparedStatement ps;
12 | private static ResultSet rs;
13 |
14 | public static ResultSet fetchData(String sql,int id)
15 | {
16 | cn=createConnection();
17 | try
18 | {
19 | ps=cn.prepareStatement(sql);
20 | ps.setInt(1, id);
21 | rs=ps.executeQuery();
22 | }
23 | catch(SQLException se)
24 | {
25 | System.out.println(se);
26 | }
27 | return rs;
28 | }
29 |
30 | public static ResultSet fetchData(String sql,String id)
31 | {
32 | cn=createConnection();
33 | try
34 | {
35 | ps=cn.prepareStatement(sql);
36 | ps.setString(1, id);
37 | rs=ps.executeQuery();
38 | }
39 | catch(SQLException se)
40 | {
41 | System.out.println(se);
42 | }
43 | return rs;
44 | }
45 |
46 | public static ResultSet fetchData(String sql)
47 | {
48 | cn=createConnection();
49 | try
50 | {
51 | ps=cn.prepareStatement(sql);
52 | rs=ps.executeQuery();
53 | }
54 | catch(SQLException se)
55 | {
56 | System.out.println(se);
57 | }
58 | return rs;
59 | }
60 |
61 | public static Connection createConnection()
62 | {
63 | ResourceBundle rb=ResourceBundle.getBundle("fks/dbinfo/database");
64 | String dbid=rb.getString("app.dbuserid");
65 | String dbpass=rb.getString("app.dbuserpass");
66 | String url=rb.getString("app.url");
67 | try
68 | {
69 | Class.forName("com.mysql.jdbc.Driver");//factory method used to create obj of a class
70 | cn=DriverManager.getConnection(url,dbid,dbpass);
71 | } //subprotocol ipaddress of machine port no
72 | //connection url or connection string
73 | catch(SQLException|ClassNotFoundException cse)
74 | {
75 | System.out.println(cse);
76 | }
77 | return cn;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/AES.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.security.MessageDigest;
5 | import java.security.NoSuchAlgorithmException;
6 | import java.util.Arrays;
7 | import java.util.Base64;
8 |
9 | import javax.crypto.Cipher;
10 | import javax.crypto.spec.SecretKeySpec;
11 |
12 | public class AES
13 | {
14 | private static SecretKeySpec secretKey;
15 | private static byte[] key;
16 |
17 | public static void setKey(String myKey)
18 | {
19 | MessageDigest sha = null;
20 | try {
21 | key = myKey.getBytes("UTF-8");
22 | sha = MessageDigest.getInstance("SHA-1");
23 | key = sha.digest(key);
24 | key = Arrays.copyOf(key, 16);
25 | secretKey = new SecretKeySpec(key, "AES");
26 | }
27 | catch (NoSuchAlgorithmException e) {
28 | e.printStackTrace();
29 | }
30 | catch (UnsupportedEncodingException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 |
35 | public static String encrypt(String strToEncrypt, String secret)
36 | {
37 | try
38 | {
39 | setKey(secret);
40 | Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
41 | cipher.init(Cipher.ENCRYPT_MODE, secretKey);
42 | return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));
43 | }
44 | catch (Exception e)
45 | {
46 | System.out.println("Error while encrypting: " + e.toString());
47 | }
48 | return null;
49 | }
50 |
51 | public static String decrypt(String strToDecrypt, String secret)
52 | {
53 | try
54 | {
55 | setKey(secret);
56 | Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
57 | cipher.init(Cipher.DECRYPT_MODE, secretKey);
58 | return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));
59 | }
60 | catch (Exception e)
61 | {
62 | System.out.println("Error while decrypting: " + e.toString());
63 | }
64 | return null;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/CryptoException.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 |
4 | public class CryptoException extends Exception
5 | {
6 | private static final long serialVersionUID = 1L;
7 | public CryptoException() {
8 | }
9 |
10 | public CryptoException(String message, Throwable throwable) {
11 | super(message, throwable);
12 | }
13 | }
--------------------------------------------------------------------------------
/fks/src/fks/servlet/CryptoUtils.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.security.InvalidKeyException;
8 | import java.security.Key;
9 | import java.security.NoSuchAlgorithmException;
10 |
11 | import javax.crypto.BadPaddingException;
12 | import javax.crypto.Cipher;
13 | import javax.crypto.IllegalBlockSizeException;
14 | import javax.crypto.NoSuchPaddingException;
15 | import javax.crypto.spec.SecretKeySpec;
16 |
17 | public class CryptoUtils {
18 | private static final String ALGORITHM = "AES";
19 | private static final String TRANSFORMATION = "AES";
20 |
21 | public static void encrypt(String key, File inputFile, File outputFile)
22 | throws CryptoException {
23 | doCrypto(Cipher.ENCRYPT_MODE, key, inputFile, outputFile);
24 | }
25 |
26 | public static void decrypt(String key, File inputFile, File outputFile)
27 | throws CryptoException {
28 | doCrypto(Cipher.DECRYPT_MODE, key, inputFile, outputFile);
29 | }
30 |
31 | private static void doCrypto(int cipherMode, String key, File inputFile,
32 | File outputFile) throws CryptoException {
33 | try {
34 | Key secretKey = new SecretKeySpec(key.getBytes(), ALGORITHM);
35 | Cipher cipher = Cipher.getInstance(TRANSFORMATION);
36 | cipher.init(cipherMode, secretKey);
37 |
38 | FileInputStream inputStream = new FileInputStream(inputFile);
39 | byte[] inputBytes = new byte[(int) inputFile.length()];
40 | inputStream.read(inputBytes);
41 |
42 | byte[] outputBytes = cipher.doFinal(inputBytes);
43 |
44 | FileOutputStream outputStream = new FileOutputStream(outputFile);
45 | outputStream.write(outputBytes);
46 |
47 | inputStream.close();
48 | outputStream.close();
49 |
50 | } catch (NoSuchPaddingException | NoSuchAlgorithmException
51 | | InvalidKeyException | BadPaddingException
52 | | IllegalBlockSizeException | IOException ex) {
53 | throw new CryptoException("Error encrypting/decrypting file", ex);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/CryptoUtilsTest.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.File;
4 |
5 | public class CryptoUtilsTest {
6 | public static void main(String[] args) {
7 | String key = "XzD51lP0QxgP74wt";
8 | File inputFile = new File("E:\\plrabn12.txt");
9 | File encryptedFile = new File("E:\\document.txt");
10 | File decryptedFile = new File("E:\\dec_document.txt");
11 | try {
12 | CryptoUtils.encrypt(key, inputFile, encryptedFile);
13 | CryptoUtils.decrypt(key, encryptedFile, decryptedFile);
14 | } catch (CryptoException ex) {
15 | System.out.println(ex.getMessage());
16 | ex.printStackTrace();
17 | }
18 | finally {
19 | System.out.println(key.length());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/Document.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.OutputStream;
9 | import java.io.PrintWriter;
10 | import java.util.Iterator;
11 | import java.util.List;
12 |
13 | import javax.servlet.ServletException;
14 | import javax.servlet.annotation.WebServlet;
15 | import javax.servlet.http.HttpServlet;
16 | import javax.servlet.http.HttpServletRequest;
17 | import javax.servlet.http.HttpServletResponse;
18 |
19 | import org.apache.commons.fileupload.FileItem;
20 | import org.apache.commons.fileupload.FileItemFactory;
21 | import org.apache.commons.fileupload.disk.DiskFileItemFactory;
22 | import org.apache.commons.fileupload.servlet.ServletFileUpload;
23 | import javax.servlet.ServletContext;
24 | import javax.servlet.annotation.MultipartConfig;
25 | import javax.servlet.http.HttpSession;
26 | import javax.servlet.http.Part;
27 |
28 | import fks.dbtasks.CrudOperation;
29 | import java.sql.*;
30 | /**
31 | * Servlet implementation class PatientReport
32 | */
33 | @WebServlet("/Document")
34 | @MultipartConfig
35 | public class Document extends HttpServlet {
36 | private static final long serialVersionUID = 1L;
37 | private Connection cn,con;
38 | private PreparedStatement ps;
39 |
40 | public Document() {
41 | super();
42 | // TODO Auto-generated constructor stub
43 | }
44 |
45 | /**
46 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
47 | */
48 |
49 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
50 | {
51 | String disk="E:\\upload\\";
52 | String file_name=null;
53 | try
54 | {
55 | PrintWriter out=response.getWriter();
56 | response.setContentType("text/html;charset=UTF-8");
57 |
58 | HttpSession hs = request.getSession(false);
59 | String uid = (String) hs.getAttribute("userid");
60 | boolean isMultiPartContent=ServletFileUpload.isMultipartContent(request);
61 | if(!isMultiPartContent)
62 | {
63 | return;
64 | }
65 | ServletFileUpload sf=new ServletFileUpload(new DiskFileItemFactory());
66 | FileItemFactory factory=new DiskFileItemFactory();
67 | ServletFileUpload upload=new ServletFileUpload(factory);
68 |
69 | List fields=upload.parseRequest(request);
70 | Iterator it=fields.iterator();
71 | if(!it.hasNext()) {
72 | return;
73 | }
74 | while(it.hasNext())
75 | {
76 | FileItem fileItem=it.next();
77 | boolean isFormField=fileItem.isFormField();
78 | if(isFormField)
79 | {
80 | if(file_name==null) {
81 | if(fileItem.getFieldName().equals("file_name")) {
82 | file_name=fileItem.getString();
83 | }
84 | }
85 | }
86 | else {
87 | if(fileItem.getSize()>0) {
88 | String query="insert into document values(?,?,?)";
89 |
90 | try {
91 | con = CrudOperation.createConnection();
92 | ps = con.prepareStatement(query);
93 | ps=cn.prepareStatement(query);
94 | ps.setString(1,uid);
95 | ps.setString(2,fileItem.getName());
96 | ps.setString(3,disk+fileItem.getName());
97 | System.out.println(ps);
98 | int rw = ps.executeUpdate();
99 | if (rw > 0)
100 | {
101 | fileItem.write(new File(disk+fileItem.getName()));
102 | System.out.println("Document(s) successfully uploaded");
103 | response.sendRedirect("/fks/jsp/docupload.jsp");
104 | }
105 | } catch (SQLException se) {
106 |
107 | System.out.println(se);
108 | }
109 |
110 | }
111 | }
112 |
113 | }
114 | }
115 | catch(Exception e)
116 | {
117 | System.out.println(e);
118 | }
119 | }
120 | /*request.getParameter("text/html");
121 | PrintWriter out=response.getWriter();
122 | String userid=request.getParameter("txtuserid");
123 | String fname=request.getParameter("txtfilename");
124 |
125 | response.setContentType("text/html;charset=UTF-8");
126 | ServletContext sc = getServletContext();
127 | String path = sc.getRealPath("/");
128 |
129 | System.out.println(path);
130 |
131 | HttpSession hs = request.getSession(false);
132 | String u_id = (String) hs.getAttribute("userkey");
133 |
134 | String newpath = path + u_id;
135 | File f1 = new File(newpath);
136 | if (!f1.exists()) {
137 |
138 | f1.mkdir();
139 | }
140 |
141 | System.out.println("directorycreated");
142 |
143 |
144 | * String description = request.getParameter("txtdesc");
145 | * System.out.println(description);
146 |
147 |
148 | final Part filePart = request.getPart("txtrep");//filecontrol
149 | final String fileName = getFileName(filePart);
150 |
151 | String query="insert into document values(?,?,?)";
152 |
153 | try {
154 | con = CrudOperation.createConnection();
155 | ps = con.prepareStatement(query);
156 | ps=cn.prepareStatement(query);
157 | ps.setString(1,userid);
158 | ps.setString(2,fname);
159 | ps.setString(3,fileName);
160 | System.out.println(ps);
161 | int rw = ps.executeUpdate();
162 | if (rw > 0) {
163 |
164 | System.out.println("Document Uploaded");
165 | response.sendRedirect("/fks/jsp/docupload.jsp");
166 | }
167 |
168 | } catch (SQLException se) {
169 |
170 | System.out.println(se);
171 | }
172 |
173 | System.out.println(fileName);
174 |
175 | OutputStream out = null;
176 | InputStream filecontent = null;
177 | final PrintWriter writer = response.getWriter();
178 |
179 | try {
180 | out = new FileOutputStream(new File(newpath + File.separator + fileName));
181 | filecontent = filePart.getInputStream();
182 |
183 | int read = 0;
184 | final byte[] bytes = new byte[1024];
185 |
186 | while ((read = filecontent.read(bytes)) != -1) {
187 | out.write(bytes, 0, read);
188 | }
189 | // writer.println("New file " + fileName + " created at " + newpath);
190 |
191 | } catch (FileNotFoundException fne) {
192 |
193 | writer.println("
ERROR: " + fne.getMessage());
194 |
195 | } finally {
196 | if (out != null) {
197 | out.close();
198 | }
199 | if (filecontent != null) {
200 | filecontent.close();
201 | }
202 | if (writer != null) {
203 | writer.close();
204 | }
205 | }
206 | }
207 |
208 | private String getFileName(final Part part) {
209 |
210 | final String partHeader = part.getHeader("content-disposition");
211 |
212 | for (String content : part.getHeader("content-disposition").split(";")) {
213 | if (content.trim().startsWith("filename")) {
214 | return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");
215 | }
216 | }
217 | return null;
218 | }*/
219 |
220 |
221 |
222 |
223 | }
224 |
225 |
226 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/EditProfile.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.RequestDispatcher;
6 | import javax.servlet.ServletException;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import javax.servlet.http.HttpSession;
12 |
13 | import fks.dbtasks.CrudOperation;
14 | import fks.servlet.AES;
15 | import java.sql.*;
16 |
17 | /**
18 | * Servlet implementation class EditProfile
19 | */
20 | @WebServlet("/EditProfile")
21 | public class EditProfile extends HttpServlet {
22 | private static final long serialVersionUID = 1L;
23 | private Connection cn;
24 | private PreparedStatement ps;
25 | /**
26 | * @see HttpServlet#HttpServlet()
27 | */
28 | public EditProfile() {
29 | super();
30 | // TODO Auto-generated constructor stub
31 | }
32 |
33 | /**
34 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
35 | */
36 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
37 | {
38 | // TODO Auto-generated method stub
39 | request.getParameter("text/html");
40 | HttpSession hs=request.getSession(false);
41 | String uid=(String)hs.getAttribute("userid");
42 | String upass=(String)hs.getAttribute("userpass");
43 | String role=(String)hs.getAttribute("role");
44 | String entpass=request.getParameter("pass");
45 | final String key="ssshhhhhhhhhhh!!!!";
46 | if(entpass.equals(upass))
47 | {
48 | String uname=request.getParameter("txtusername");
49 | String mail=request.getParameter("txtmail");
50 | try {
51 | cn=CrudOperation.createConnection();
52 | cn.setAutoCommit(false);
53 | String login="update logininfo set username=?, email=? where userid=?";
54 | ps=cn.prepareStatement(login);
55 | ps.setString(1,AES.encrypt(uname, key));
56 | ps.setString(2,AES.encrypt(mail, key));
57 | ps.setString(3,uid);
58 | int rw = ps.executeUpdate();
59 | if (rw > 0)
60 | {
61 | cn.commit();
62 | request.setAttribute("msg", "Profile updated successfully");
63 | if(role.equals("dataowner"))
64 | {
65 | RequestDispatcher rd=request.getRequestDispatcher("/doedit.jsp");
66 | rd.forward(request, response);
67 | }
68 | else
69 | {
70 | RequestDispatcher rd=request.getRequestDispatcher("/uedit.jsp");
71 | rd.forward(request, response);
72 | }
73 | }
74 | }
75 | catch (SQLException se)
76 | {
77 | System.out.println(se);
78 | }
79 | }
80 | else
81 | {
82 | request.setAttribute("msg", "Wrong Password");
83 | if(role.equals("dataowner"))
84 | {
85 | RequestDispatcher rd=request.getRequestDispatcher("/doedit.jsp");
86 | rd.forward(request, response);
87 | }
88 | else
89 | {
90 | RequestDispatcher rd=request.getRequestDispatcher("/uedit.jsp");
91 | rd.forward(request, response);
92 | }
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/fks/src/fks/servlet/EmailUtility.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.util.Date;
4 | import java.util.Properties;
5 |
6 | import javax.mail.Authenticator;
7 | import javax.mail.Message;
8 | import javax.mail.MessagingException;
9 | import javax.mail.PasswordAuthentication;
10 | import javax.mail.Session;
11 | import javax.mail.Transport;
12 | import javax.mail.internet.AddressException;
13 | import javax.mail.internet.InternetAddress;
14 | import javax.mail.internet.MimeMessage;
15 |
16 | public class EmailUtility {
17 | public static void sendEmail(String host, String port,
18 | final String userName, final String password, String toAddress,
19 | String subject, String message) throws AddressException,
20 | MessagingException {
21 |
22 | // sets SMTP server properties
23 | Properties properties = new Properties();
24 | properties.put("mail.smtp.host", host);
25 | properties.put("mail.smtp.port", port);
26 | properties.put("mail.smtp.ssl.trust", "smtp.gmail.com");
27 | properties.put("mail.smtp.auth", "true");
28 | properties.put("mail.smtp.starttls.enable", "true");
29 |
30 | // creates a new session with an authenticator
31 | Authenticator auth = new Authenticator() {
32 | public PasswordAuthentication getPasswordAuthentication() {
33 | return new PasswordAuthentication(userName, password);
34 | }
35 | };
36 |
37 | Session session = Session.getInstance(properties, auth);
38 |
39 | // creates a new e-mail message
40 | Message msg = new MimeMessage(session);
41 |
42 | msg.setFrom(new InternetAddress(userName));
43 | InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
44 | msg.setRecipients(Message.RecipientType.TO, toAddresses);
45 | msg.setSubject(subject);
46 | msg.setSentDate(new Date());
47 | msg.setText(message);
48 |
49 | Transport.send(msg);
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/FileUploadHandle.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.PrintWriter;
6 | import java.util.Iterator;
7 | import java.util.List;
8 |
9 | import javax.servlet.ServletException;
10 | import javax.servlet.annotation.WebServlet;
11 | import javax.servlet.http.HttpServlet;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import javax.servlet.http.HttpSession;
15 |
16 | import org.apache.commons.fileupload.FileItem;
17 | import org.apache.commons.fileupload.FileItemFactory;
18 | import org.apache.commons.fileupload.disk.DiskFileItemFactory;
19 | import org.apache.commons.fileupload.servlet.ServletFileUpload;
20 |
21 | import fks.servlet.AES;
22 | import fks.dbtasks.CrudOperation;
23 | import java.sql.*;
24 | /**
25 | * Servlet implementation class FileUploadHandle
26 | */
27 | @WebServlet("/FileUploadHandle")
28 | public class FileUploadHandle extends HttpServlet {
29 | private static final long serialVersionUID = 1L;
30 | private Connection con;
31 | private PreparedStatement ps;
32 | /**
33 | * @see HttpServlet#HttpServlet()
34 | */
35 | public FileUploadHandle() {
36 | super();
37 | // TODO Auto-generated constructor stub
38 | }
39 | /**
40 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
41 | */
42 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
43 | // TODO Auto-generated method stub
44 | response.getWriter().append("Served at: ").append(request.getContextPath());
45 | }
46 |
47 | /**
48 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
49 | */
50 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
51 |
52 | String file_name = null;
53 | response.setContentType("text/html");
54 | PrintWriter out = response.getWriter();
55 | boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
56 | if (!isMultipartContent) {
57 | return;
58 | }
59 | FileItemFactory factory = new DiskFileItemFactory();
60 | ServletFileUpload upload = new ServletFileUpload(factory);
61 | try {
62 | List < FileItem > fields = upload.parseRequest(request);
63 | Iterator < FileItem > it = fields.iterator();
64 | if (!it.hasNext()) {
65 | return;
66 | }
67 | while (it.hasNext()) {
68 | FileItem fileItem = it.next();
69 | boolean isFormField = fileItem.isFormField();
70 | if (isFormField) {
71 | if (file_name == null) {
72 | if (fileItem.getFieldName().equals("txtfilename")) {
73 | file_name = fileItem.getString();
74 | }
75 | }
76 | } else {
77 | if (fileItem.getSize() > 0) {
78 | HttpSession hs = request.getSession(false);
79 | String uid = (String) hs.getAttribute("userid");
80 | String key = (String) hs.getAttribute("userkey");
81 | String query="insert into document values(?,?,?,?)";
82 |
83 | try {
84 | String enfname = AES.encrypt(fileItem.getName(), key) ;
85 | //System.out.println(enfname);
86 | String enfpath = AES.encrypt("E:\\upload\\"+fileItem.getName(), key) ;
87 | //System.out.println(enfpath);
88 | con = CrudOperation.createConnection();
89 | ps = con.prepareStatement(query);
90 | ps.setString(1,uid);
91 | ps.setString(2,enfname);
92 | ps.setString(3,enfpath);
93 | ps.setString(4,key);
94 | //System.out.println(ps);
95 | fileItem.write(new File("E:\\upload\\" + fileItem.getName()));
96 | File inputFile = new File("E:\\upload\\" + fileItem.getName());
97 | File encryptedFile = new File("E:\\upload\\" + enfname);
98 |
99 | try
100 | {
101 | CryptoUtils.encrypt(key, inputFile, encryptedFile);
102 | inputFile.delete();
103 | }
104 | catch (CryptoException ex) {
105 | System.out.println(ex.getMessage());
106 | ex.printStackTrace();
107 | }
108 |
109 | int rw = ps.executeUpdate();
110 | if (rw > 0)
111 | {
112 | System.out.println("Document(s) successfully uploaded.");
113 | }
114 |
115 | } catch (SQLException se) {
116 |
117 | System.out.println(se);
118 | }
119 |
120 |
121 | }
122 | }
123 | }
124 | } catch (Exception e) {
125 | e.printStackTrace();
126 | } finally {
127 | out.println("");
130 | out.close();
131 | }
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/Login.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.IOException;
4 | import java.sql.Connection;
5 | import java.sql.PreparedStatement;
6 | import java.sql.ResultSet;
7 | import java.sql.SQLException;
8 |
9 | import javax.servlet.RequestDispatcher;
10 | import javax.servlet.ServletException;
11 | import javax.servlet.annotation.WebServlet;
12 | import javax.servlet.http.HttpServlet;
13 | import javax.servlet.http.HttpServletRequest;
14 | import javax.servlet.http.HttpServletResponse;
15 | import javax.servlet.http.HttpSession;
16 |
17 | import fks.servlet.AES;
18 | import fks.dbtasks.CrudOperation;
19 | /**
20 | * Servlet implementation class Login
21 | */
22 | @WebServlet("/Login")
23 | public class Login extends HttpServlet {
24 | private static final long serialVersionUID = 1L;
25 | private Connection cn;
26 | private PreparedStatement pslogin;
27 | private ResultSet rslogin;
28 |
29 | /**
30 | * @see HttpServlet#HttpServlet()
31 | */
32 | public Login() {
33 | super();
34 | // TODO Auto-generated constructor stub
35 | }
36 |
37 |
38 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
39 | }
40 |
41 | /**
42 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
43 | */
44 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
45 | {
46 | String id=request.getParameter("txtuserid").trim();
47 | String pass=request.getParameter("txtuserpass");
48 | cn=CrudOperation.createConnection();
49 | String strsql="select * from logininfo where userid=?";
50 | try
51 | {
52 | pslogin=cn.prepareStatement(strsql);
53 | pslogin.setString(1, id);
54 | rslogin=pslogin.executeQuery();
55 | if(rslogin.next())
56 | {
57 | String enpass=rslogin.getString("userpass");
58 | final String secretKey = "ssshhhhhhhhhhh!!!!";
59 | String depass = AES.decrypt(enpass, secretKey);
60 | if(depass.equals(pass))
61 | {
62 | HttpSession hs=request.getSession(); //create new session
63 | String utype=rslogin.getString("role");
64 | String umail=rslogin.getString("email");
65 | hs.setAttribute("userid", id);
66 | hs.setAttribute("userpass", utype);
67 | hs.setAttribute("usermail", umail);
68 | if(utype.equalsIgnoreCase("dataowner"))
69 | {
70 | String key=rslogin.getString("key");
71 | hs.setAttribute("userkey", key);
72 | response.sendRedirect("/fks/dataowner_home.jsp");
73 | }
74 | else if(utype.equalsIgnoreCase("user"))
75 | response.sendRedirect("/fks/user_home.jsp");
76 | else if(utype.equalsIgnoreCase("cloudadmin"))
77 | response.sendRedirect("/fks/cloud_home.jsp");
78 | }
79 | else
80 | {
81 | request.setAttribute("msg", "Invalid Password");
82 | RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");
83 | rd.forward(request, response);
84 | }
85 | }
86 | else
87 | {
88 | request.setAttribute("msg", "Invalid UserID or Password");
89 | RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");
90 | rd.forward(request, response);
91 | }
92 | }
93 | catch(SQLException se)
94 | {
95 | System.out.println(se);
96 | }
97 |
98 |
99 | }
100 |
101 | }
102 | /*FileUploadServletExample
103 |
104 | FileUpload
105 | FileUpload
106 | fks.servlet.FileUpload
107 |
108 |
109 | FileUpload
110 | /uploadFile
111 | */
112 |
113 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/Logoff.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.IOException;
4 | import javax.servlet.ServletException;
5 | import javax.servlet.annotation.WebServlet;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 | import javax.servlet.http.HttpSession;
10 |
11 | /**
12 | * Servlet implementation class Logoff
13 | */
14 | @WebServlet("/Logoff")
15 | public class Logoff extends HttpServlet {
16 | private static final long serialVersionUID = 1L;
17 |
18 | /**
19 | * @see HttpServlet#HttpServlet()
20 | */
21 | public Logoff() {
22 | super();
23 | // TODO Auto-generated constructor stub
24 | }
25 |
26 | /**
27 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
28 | */
29 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
30 | {
31 | doPost(request,response);
32 | }
33 |
34 | /**
35 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
36 | */
37 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
38 | {
39 | HttpSession hs=request.getSession(false);
40 | String ui=(String)hs.getAttribute("userid");
41 | hs.removeAttribute("userid");
42 | hs.invalidate();//destroys the session for current user
43 | response.sendRedirect("/fks/login.jsp");
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/Reg.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 | import java.sql.SQLException;
6 |
7 | import javax.servlet.ServletContext;
8 | import javax.servlet.ServletException;
9 | import javax.servlet.annotation.WebServlet;
10 | import javax.servlet.http.HttpServlet;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 |
14 | import java.io.UnsupportedEncodingException;
15 | import java.nio.charset.Charset;
16 | import java.security.MessageDigest;
17 | import java.security.NoSuchAlgorithmException;
18 | import java.util.Arrays;
19 | import java.util.Base64;
20 | import java.util.Random;
21 |
22 | import javax.crypto.Cipher;
23 | import javax.crypto.spec.SecretKeySpec;
24 |
25 | import fks.dbtasks.CrudOperation;
26 | import fks.servlet.EmailUtility;
27 |
28 | import java.sql.*;
29 | /**
30 | * Servlet implementation class PatientRegistration
31 | */
32 | @WebServlet("/Reg")
33 | public class Reg extends HttpServlet {
34 | private static final long serialVersionUID = 1L;
35 | private Connection cn;
36 | private PreparedStatement ps1,ps2;
37 | private String host;
38 | private String port;
39 | private String user;
40 | private String pass;
41 |
42 | public void init() {
43 | // reads SMTP server setting from web.xml file
44 | ServletContext context = getServletContext();
45 | host = context.getInitParameter("host");
46 | port = context.getInitParameter("port");
47 | user = context.getInitParameter("user");
48 | pass = context.getInitParameter("pass");
49 | }
50 |
51 | /**
52 | * @see HttpServlet#HttpServlet()
53 | */
54 | public Reg() {
55 | super();
56 | // TODO Auto-generated constructor stub
57 | }
58 |
59 | public static String getAlphaNumericString(int n)
60 | {
61 | byte[] array = new byte[256];
62 | new Random().nextBytes(array);
63 |
64 | String randomString
65 | = new String(array, Charset.forName("UTF-8"));
66 |
67 | StringBuffer r = new StringBuffer();
68 |
69 | for (int k = 0; k < randomString.length(); k++) {
70 |
71 | char ch = randomString.charAt(k);
72 |
73 | if (((ch >= 'a' && ch <= 'z')
74 | || (ch >= 'A' && ch <= 'Z')
75 | || (ch >= '0' && ch <= '9'))
76 | && (n > 0)) {
77 |
78 | r.append(ch);
79 | n--;
80 | }
81 | }
82 | return r.toString();
83 | }
84 |
85 | /**
86 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
87 | */
88 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
89 | // TODO Auto-generated method stub
90 | response.getWriter().append("Served at: ").append(request.getContextPath());
91 | }
92 |
93 | /**
94 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
95 | */
96 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
97 | {
98 | request.getParameter("text/html");
99 | PrintWriter out=response.getWriter();
100 | String id=request.getParameter("txtuserid");
101 | String ps=request.getParameter("pass");
102 | String name=request.getParameter("txtusername");
103 | String mail=request.getParameter("txtmail");
104 | String role=request.getParameter("role");
105 |
106 | final String secretKey = "ssshhhhhhhhhhh!!!!";
107 |
108 | String enpass = AES.encrypt(ps, secretKey) ;
109 | String enname = AES.encrypt(name, secretKey) ;
110 | String enmail = AES.encrypt(mail, secretKey) ;
111 | String resultMessage = "";
112 | //System.out.println(id);
113 | //System.out.println(enpass);
114 |
115 | try {
116 | cn=CrudOperation.createConnection();
117 | cn.setAutoCommit(false);
118 | String login="insert into logininfo values(?,?,?,?,?,?)";
119 | ps1=cn.prepareStatement(login);
120 | ps1.setString(1,id);
121 | ps1.setString(2,enpass);
122 | ps1.setString(3,enname);
123 | ps1.setString(4,enmail);
124 | ps1.setString(5,role);
125 | if(role.equalsIgnoreCase("user"))
126 | {
127 | ps1.setString(6,null);
128 | String auth="insert into auth values(?,?)";
129 | ps2=cn.prepareStatement(auth);
130 | ps2.setString(1, id);
131 | ps2.setString(2, "no");
132 | ps2.executeUpdate();
133 | }
134 | else
135 | ps1.setString(6,getAlphaNumericString(16));
136 | int rw = ps1.executeUpdate();
137 | if (rw > 0)
138 | {
139 | cn.commit();
140 | EmailUtility.sendEmail(host, port, user, pass, mail, "Welcome to our platform as a "+role,
141 | "Hi, "+name+"\nYour User ID: "+id+"\nYour password: "+ps);
142 | resultMessage = "Registration successful, you will receive an e-mail shortly.";
143 | }
144 | }
145 | catch (SQLException se)
146 | {
147 | System.out.println(se);
148 | }
149 | catch (Exception ex)
150 | {
151 | ex.printStackTrace();
152 | resultMessage = "There were an error: " + ex.getMessage();
153 | }
154 | finally
155 | {
156 | request.setAttribute("Message", resultMessage);
157 | getServletContext().getRequestDispatcher("/Result.jsp").forward(
158 | request, response);
159 | }
160 |
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/fks/src/fks/servlet/edst.java:
--------------------------------------------------------------------------------
1 | package fks.servlet;
2 |
3 | import java.util.Arrays;
4 |
5 | public class edst
6 | {
7 | public static int calculate(String x, String y)
8 | {
9 | if (x.isEmpty()) {
10 | return y.length();
11 | }
12 |
13 | if (y.isEmpty()) {
14 | return x.length();
15 | }
16 |
17 | int substitution = calculate(x.substring(1), y.substring(1))
18 | + costOfSubstitution(x.charAt(0), y.charAt(0));
19 | int insertion = calculate(x, y.substring(1)) + 1;
20 | int deletion = calculate(x.substring(1), y) + 1;
21 |
22 | return min(substitution, insertion, deletion);
23 | }
24 |
25 | public static int costOfSubstitution(char a, char b)
26 | {
27 | return a == b ? 0 : 1;
28 | }
29 |
30 | public static int min(int... numbers)
31 | {
32 | return Arrays.stream(numbers)
33 | .min().orElse(Integer.MAX_VALUE);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------