Archive for the ‘password encryption’ tag
Simple Password Encryption Technique - Java
Here’s a simple Password Encryption technique using hashCode(), It is just a basic style that does not expose your password in the source code. The Password I have set is - password
import java.io.Console;
public class pwd {
public static void main(String[] args) {
char[] passwordChar = null;
Console console = System.console();
int hashInt = 1216985755; // value of the string “password”
try {
passwordChar = console.readPassword(”Enter Password : “);
} catch (NullPointerException e) {
System.out.println(”You Might Be Running The Program From An IDE , Try In Terminal”);
System.exit(1);
}
String passwordString = new String(passwordChar);
System.out.println(”The Hash value of the Entered String : ”
+ passwordString.hashCode());
System.out.println(”The Hash Value Required : ” + hashInt);
if (passwordString.hashCode() != hashInt) { // hash coded check
System.out.println(”Wrong password”);
System.exit(2);
}
System.out.println(”Correct Password”);
}
}
There are better ways to do it than hashcode() method which is fragile, md5 or sha1 would be better techniques. The ONE TIME PADDING or encrypting the password using a secret key and storing it, but just for the program access I dont think it is that necessary, but the latter techniques will be useful while transmitting messages.

