// Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
// 
// 	private CharSequence passPhrase;	
// 	private int actionNumber;
// 	
// 	public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// 		this.passPhrase = passPhrase;
// 		this.actionNumber = actionNumber;
// 	}
// 	
// 	public String getKnock() {
// 		byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// 		byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
// 		
// 		byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
// 		
// 		return Base64.encodeBase64URLSafeString(allBytes);
// 	}
// 
// 	public static String encode(CharSequence passPhrase) {
// 		byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// 		return Base64.encodeBase64URLSafeString(passKnockBytes);
// 	}
// 
// 	public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
// 
// 		if(webSpaRequest.length() != 100) {
// 			
// 			return false;
// 			
// 		} else {
// 			
// 			byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// 			byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// 			byte randomByte = webSpaBytes[0];
// 			
// 			byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
// 			
// 			return WebSpaUtils.equals(passBytes, expectedBytes);
// 		}
// 	}
// 	
// 	public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
// 		
// 		int returnAction = -1;
// 		
// 		if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
// 			
// 			byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// 			byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// 			byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
// 						
// 			for(int count = 0; count <= 9; count++) {
// 				
// 				byte[] calculatedActionBytes = 
// 						ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
// 				
// 				if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// 					returnAction = count;
// 					break;
// 				}
// 				
// 			} // for loop
// 		}
// 		
// 		return returnAction;
// 	}
// 
// }


import java.nio.CharBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.seleucus.wsp.crypto.WebSpaEncoder;
				
				ps.executeUpdate();
				
			} catch (SQLException ex) {
				
				 LOGGER.error("Toggle User Activation - A Database exception has occured: {}.", ex.getMessage());	
				
			}
			
		} // ppID > 0
		
		return success;
		
	}

	public synchronized int getPPIDFromRequest(final String webSpaRequest) {
		
		int output = -1;
		final String sqlPassPhrases = "SELECT PASSPHRASE, PPID FROM PASSPHRASES;";
		
		try {
			Statement stmt = wsConnection.createStatement();
			ResultSet rs = stmt.executeQuery(sqlPassPhrases);
	
			while (rs.next()) {
				
				char[] dbPassPhraseArray = rs.getString(1).toCharArray();
				final int dbPPID = rs.getInt(2);
				CharSequence rawPassword = CharBuffer.wrap(dbPassPhraseArray);
				
// Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
// 
// 	private CharSequence passPhrase;	
// 	private int actionNumber;
// 	
// 	public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// 		this.passPhrase = passPhrase;
// 		this.actionNumber = actionNumber;
// 	}
// 	
// 	public String getKnock() {
// 		byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// 		byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
// 		
// 		byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
// 		
// 		return Base64.encodeBase64URLSafeString(allBytes);
// 	}
// 
// 	public static String encode(CharSequence passPhrase) {
// 		byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// 		return Base64.encodeBase64URLSafeString(passKnockBytes);
// 	}
// 
// 	public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
// 
// 		if(webSpaRequest.length() != 100) {
// 			
// 			return false;
// 			
// 		} else {
// 			
// 			byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// 			byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// 			byte randomByte = webSpaBytes[0];
// 			
// 			byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
// 			
// 			return WebSpaUtils.equals(passBytes, expectedBytes);
// 		}
// 	}
// 	
// 	public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
// 		
// 		int returnAction = -1;
// 		
// 		if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
// 			
// 			byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// 			byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// 			byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
// 						
// 			for(int count = 0; count <= 9; count++) {
// 				
// 				byte[] calculatedActionBytes = 
// 						ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
// 				
// 				if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// 					returnAction = count;
// 					break;
// 				}
// 				
// 			} // for loop
// 		}
// 		
// 		return returnAction;
// 	}
// 
// }


// Path: src/main/java/net/seleucus/wsp/db/WSPassPhrases.java
import java.nio.CharBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.seleucus.wsp.crypto.WebSpaEncoder;

				
				ps.executeUpdate();
				
			} catch (SQLException ex) {
				
				 LOGGER.error("Toggle User Activation - A Database exception has occured: {}.", ex.getMessage());	
				
			}
			
		} // ppID > 0
		
		return success;
		
	}

	public synchronized int getPPIDFromRequest(final String webSpaRequest) {
		
		int output = -1;
		final String sqlPassPhrases = "SELECT PASSPHRASE, PPID FROM PASSPHRASES;";
		
		try {
			Statement stmt = wsConnection.createStatement();
			ResultSet rs = stmt.executeQuery(sqlPassPhrases);
	
			while (rs.next()) {
				
				char[] dbPassPhraseArray = rs.getString(1).toCharArray();
				final int dbPPID = rs.getInt(2);
				CharSequence rawPassword = CharBuffer.wrap(dbPassPhraseArray);
				
				if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {