Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 95a448c
Showing
243 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
|
||
public abstract class Database{ | ||
|
||
// add the username and password pair to the database | ||
public static void addUsernameAndPasswordToDatabase(String username, String password) throws Exception{ | ||
Class.forName("org.sqlite.JDBC"); | ||
Connection conn = DriverManager.getConnection("jdbc:sqlite:pass_hash.db"); | ||
|
||
PreparedStatement statement = conn.prepareStatement("insert into passwords values (?, ?);"); | ||
statement.setString(1, username); | ||
statement.setString(2, password); | ||
statement.addBatch(); | ||
|
||
conn.setAutoCommit(false); | ||
statement.executeBatch(); | ||
conn.setAutoCommit(true); | ||
|
||
conn.close(); | ||
} | ||
|
||
// create the database and tables if they don't already exist | ||
public static void createDatabase() throws Exception{ | ||
Class.forName("org.sqlite.JDBC"); | ||
Connection conn = DriverManager.getConnection("jdbc:sqlite:pass_hash.db"); | ||
Statement stat = conn.createStatement(); | ||
stat.executeUpdate("create table if not exists passwords (username, password);"); | ||
conn.close(); | ||
} | ||
|
||
public static String[][] getAllUsernameAndPasswordPairs() throws Exception{ | ||
int numRows = Database.numRowsInDB(); | ||
String result[][] = new String[numRows][2]; | ||
int index = 0; | ||
|
||
Class.forName("org.sqlite.JDBC"); | ||
Connection conn = DriverManager.getConnection("jdbc:sqlite:pass_hash.db"); | ||
Statement stat = conn.createStatement(); | ||
|
||
ResultSet rs = stat.executeQuery("select * from passwords;"); | ||
|
||
while (rs.next() && index<numRows){ | ||
result[index][0] = rs.getString("username"); | ||
result[index][1] = rs.getString("password"); | ||
index++; | ||
} | ||
|
||
rs.close(); | ||
conn.close(); | ||
|
||
return result; | ||
} | ||
|
||
public static int numRowsInDB() throws Exception{ | ||
Class.forName("org.sqlite.JDBC"); | ||
Connection conn = DriverManager.getConnection("jdbc:sqlite:pass_hash.db"); | ||
Statement stat = conn.createStatement(); | ||
ResultSet rs = stat.executeQuery("select count(*) from passwords;"); | ||
|
||
int result = rs.getInt(1); | ||
|
||
rs.close(); | ||
conn.close(); | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* This class simply uses the other classes to take in the username/password | ||
* and show how everything works. | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class DatabaseTester{ | ||
public static void main(String[] args) throws Exception{ | ||
Scanner keyboard = new Scanner(System.in); | ||
System.out.println("DatabaseTester - Let's encrypt and store some words"); | ||
|
||
System.out.print("Enter your username: "); | ||
String username = keyboard.nextLine(); | ||
|
||
System.out.print("Enter your password: "); | ||
String password = keyboard.nextLine(); | ||
|
||
System.out.println("Your username: " + username + "\nYour password: " + password); | ||
|
||
// the Password class automatically encrypts the password when you instantiate it | ||
// the constructor takes a string | ||
Password passwd = new Password(password); | ||
|
||
// Password's toString method returns the encrypted password | ||
System.out.println("Your encrypted password: " + passwd); | ||
|
||
// This is how you decrypt the password stored in the object | ||
System.out.println("Your decrypted password: " + passwd.getDecryptedPassword()); | ||
|
||
// Password also has a static method to decrypt a formerly encrypyted/stored string | ||
System.out.println("Your decrypted password with Password's static method: " + Password.decryptPassword(passwd.toString())); | ||
|
||
// when we first run the program, we'll need to create the database | ||
// createDatabase() only creates it if it doesn't already exist | ||
// Database is abstract, so don't try to instantiate it | ||
Database.createDatabase(); | ||
|
||
// to add a username and password to the database, just use this method | ||
Database.addUsernameAndPasswordToDatabase(username, passwd.toString()); | ||
|
||
// this method will return all the rows of the database in a 2-dimensional array | ||
String passwords[][] = Database.getAllUsernameAndPasswordPairs(); | ||
|
||
// this just prints the pairs | ||
System.out.println("Here's all the pairs in the database!!"); | ||
for(int i=0; i<passwords.length; i++){ | ||
for(int j=0; j<passwords[i].length; j++){ | ||
System.out.print(passwords[i][j] + " "); | ||
} | ||
System.out.print("\n"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* This class encrypts a password upon object creation and | ||
* can decrypt it as well. It also decrypts a string. | ||
*/ | ||
|
||
import org.jasypt.util.text.*; | ||
|
||
public class Password{ | ||
private String password; | ||
private static final String ENCRYPTOR_PASSWORD = "passhash and kittens 4ever"; | ||
private BasicTextEncryptor encryptor = new BasicTextEncryptor(); | ||
|
||
public Password(String newPassword){ | ||
encryptor.setPassword(ENCRYPTOR_PASSWORD); | ||
String encryptedPassword = encryptor.encrypt(newPassword); | ||
password = encryptedPassword; | ||
} | ||
|
||
public String getDecryptedPassword(){ | ||
return (String) encryptor.decrypt(this.password); | ||
} | ||
|
||
public String getEncryptedPassword(){ | ||
return (String) password; | ||
} | ||
|
||
public String toString(){ | ||
return (String) this.getEncryptedPassword(); | ||
} | ||
|
||
public static String decryptPassword(String encryptedPassword){ | ||
BasicTextEncryptor encryptor2 = new BasicTextEncryptor(); | ||
encryptor2.setPassword(ENCRYPTOR_PASSWORD); | ||
return (String) encryptor2.decrypt(encryptedPassword); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+337 Bytes
org/jasypt/contrib/org/apache/commons/codec_1_3/BinaryDecoder.class
Binary file not shown.
Binary file added
BIN
+337 Bytes
org/jasypt/contrib/org/apache/commons/codec_1_3/BinaryEncoder.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+437 Bytes
org/jasypt/contrib/org/apache/commons/codec_1_3/DecoderException.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+437 Bytes
org/jasypt/contrib/org/apache/commons/codec_1_3/EncoderException.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+746 Bytes
org/jasypt/exceptions/EncryptionOperationNotPossibleException.class
Binary file not shown.
Binary file added
BIN
+2.24 KB
org/jasypt/hibernate/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.class
Binary file not shown.
Binary file added
BIN
+2.28 KB
...asypt/hibernate/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.47 KB
org/jasypt/spring/properties/EncryptablePreferencesPlaceholderConfigurer.class
Binary file not shown.
Binary file added
BIN
+1.44 KB
org/jasypt/spring/properties/EncryptablePropertyOverrideConfigurer.class
Binary file not shown.
Binary file added
BIN
+1.45 KB
org/jasypt/spring/properties/EncryptablePropertyPlaceholderConfigurer.class
Binary file not shown.
Binary file added
BIN
+1.51 KB
org/jasypt/spring/properties/EncryptableServletContextPropertyPlaceholderConfigurer.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.