0

I'm trying to generated a salted password on Java, and I'm having issues trying to print out the string "password" when I run the program and print password is just empty.

import java.util.Scanner;
import java.util.Random;

public class SaltPassword {
public static void main (String[] args) {
    saltIt();
}

public static void saltIt() {
    //initiate sacnner
    Scanner sc = new Scanner(System.in);
    
    //Prompt the user for and int save as 'seed'
    System.out.println("Enter seed:");
    int seed = sc.nextInt();
    
    //Prompt the user for a string, save as 'password'
    System.out.println("Enter a password:");
    String password = sc.nextLine();
    sc.nextLine();
    
    //generating variables for randoms numbers
    Random random = new Random(seed);
    char min = 65;
    char max = 122;
    char salt = ( (char)(random.nextInt(max - min + 1) + (min)) );
    char salt1 = ( (char)(random.nextInt(max - min + 1) + (min)) );
    char salt2 = ( (char)(random.nextInt(max - min + 1) + (min)) );
    char salt3 = ( (char)(random.nextInt(max - min + 1) + (min)) );
    char salt4 = ( (char)(random.nextInt(max - min + 1) + (min)) );
    System.out.println("Salt: " + salt + salt1 + salt2 + salt3 + salt4);
    
    //generating salted password 
    String saltedPassword = ((password) + salt + salt1 + salt2 + salt3 +salt4);
    System.out.println("Salted password:" + saltedPassword )
    
    //Close scanner
    sc.close();
David Conrad
  • 15,432
  • 2
  • 42
  • 54

0 Answers0