<commit_before>package net.jingx.main;

import java.awt.EventQueue;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class MainGui {

	private static String PATH_GAUTH_SECKEY = System.getProperty("user.home") + "/" + ".gauth" + "/";
	private static String SEC_FILENAME = "sec";
	
	private JFrame frmPinGenerator;
	private JTextField txtSecretKey;
	private JTextField txtPin;
	private JButton btnSaveSecret;
	private static final int MIN_KEY_BYTES = 10;
	private JLabel lblTimersec;
	private TimerNextKey timerNextKey;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainGui window = new MainGui();
					window.frmPinGenerator.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainGui() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		String secret = readSecret();
		frmPinGenerator = new JFrame();
		frmPinGenerator.setTitle("Pin Generator");
		frmPinGenerator.setBounds(100, 100, 286, 93);
		frmPinGenerator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmPinGenerator.getContentPane().setLayout(null);
		
		JLabel lblSecretKey = new JLabel("Secret Key:");
		lblSecretKey.setBounds(25, 12, 68, 16);
		frmPinGenerator.getContentPane().add(lblSecretKey);
		
		txtSecretKey = new JTextField();
		txtSecretKey.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent arg0) {
				if(txtSecretKey.getText() != null && !txtSecretKey.getText().equals("")){
					timerNextKey.restart();
					generateAndDisplayPin();
				}else{
					timerNextKey.stop();
				}
			}
		});
		txtSecretKey.setBounds(95, 6, 134, 28);
		frmPinGenerator.getContentPane().add(txtSecretKey);
		txtSecretKey.setColumns(10);
		
		JLabel lblPin = new JLabel("Pin:");
		lblPin.setBounds(70, 46, 23, 16);
		frmPinGenerator.getContentPane().add(lblPin);

		txtPin = new JTextField();
		txtPin.setBackground(SystemColor.window);
		txtPin.setEditable(false);
		txtPin.setBounds(95, 40, 134, 28);
		txtPin.setBorder(javax.swing.BorderFactory.createEmptyBorder());
		frmPinGenerator.getContentPane().add(txtPin);
		txtPin.setColumns(10);
		
		btnSaveSecret = new JButton("");
		btnSaveSecret.setBorder(javax.swing.BorderFactory.createEmptyBorder());
		btnSaveSecret.setIcon(new ImageIcon(MainGui.class.getResource("/net/jingx/icons/disk.png")));
		btnSaveSecret.setBounds(227, 7, 29, 29);
		btnSaveSecret.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String secret = txtSecretKey.getText();
				if(secret!=null && !secret.equals("")){
					saveSecret(secret);	
				}
			}
		});
		frmPinGenerator.getContentPane().add(btnSaveSecret);
		
		lblTimersec = new JLabel("");
		lblTimersec.setBounds(237, 46, 43, 16);
		frmPinGenerator.getContentPane().add(lblTimersec);
		
		timerNextKey = new TimerNextKey(lblTimersec, makeTimerAction());
		if(secret!=null){
			txtSecretKey.setText(secret);
			timerNextKey.start();
		}
		generateAndDisplayPin();
		frmPinGenerator.addWindowFocusListener(new WindowAdapter() {
		    public void windowGainedFocus(WindowEvent e) {
		    	txtPin.requestFocusInWindow();
		    }
		});

	}
	
	private String readSecret(){
		try{
			String secret = null;
			File fSec = new File(PATH_GAUTH_SECKEY + SEC_FILENAME);
			if(fSec.exists()){
				 FileReader fr = new FileReader(fSec);
				 BufferedReader br = new BufferedReader(fr);
				 secret = br.readLine();
				 br.close();
			}
			return secret;
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	private void saveSecret(String secret){
		try{
			File fDirGAuth = new File(PATH_GAUTH_SECKEY);
			fDirGAuth.mkdirs();
			FileWriter fw = new FileWriter(PATH_GAUTH_SECKEY + SEC_FILENAME);
			fw.write(secret);
			fw.flush();
			fw.close();
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public void doSetVisible() {
		frmPinGenerator.setVisible(true);
	}
	
	private ActionListener makeTimerAction() {
		ActionListener a = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				generateAndDisplayPin();
			}
		};
		return a;
	}
		
	private void generateAndDisplayPin(){
		String secret = txtSecretKey.getText();
		if(secret!=null && !secret.equals("")){
			if(secret.length() < MIN_KEY_BYTES){
				txtPin.setText("Key is too short");
				if(timerNextKey.isRunning()){
					timerNextKey.stop();
				}
			}else{
				txtPin.setText(Main.computePin(txtSecretKey.getText(), null));
			}
		}
	}
}<commit_msg>using password field for secret key<commit_after>package net.jingx.main;

import java.awt.EventQueue;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class MainGui {

	private static String PATH_GAUTH_SECKEY = System.getProperty("user.home") + "/" + ".gauth" + "/";
	private static String SEC_FILENAME = "sec";
	
	private JFrame frmPinGenerator;
	private JPasswordField txtSecretKey;
	private JTextField txtPin;
	private JButton btnSaveSecret;
	private static final int MIN_KEY_BYTES = 10;
	private JLabel lblTimersec;
	private TimerNextKey timerNextKey;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainGui window = new MainGui();
					window.frmPinGenerator.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainGui() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		String secret = readSecret();
		frmPinGenerator = new JFrame();
		frmPinGenerator.setTitle("Pin Generator");
		frmPinGenerator.setBounds(100, 100, 286, 93);
		frmPinGenerator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmPinGenerator.getContentPane().setLayout(null);
		
		JLabel lblSecretKey = new JLabel("Secret Key:");
		lblSecretKey.setBounds(25, 12, 68, 16);
		frmPinGenerator.getContentPane().add(lblSecretKey);
		
		txtSecretKey = new JPasswordField();
		txtSecretKey.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent arg0) {
				String secret = new String(txtSecretKey.getPassword());
				if(secret != null && !secret.equals("")){
					timerNextKey.restart();
					generateAndDisplayPin();
				}else{
					timerNextKey.stop();
				}
			}
		});
		txtSecretKey.setBounds(95, 6, 134, 28);
		frmPinGenerator.getContentPane().add(txtSecretKey);
		txtSecretKey.setColumns(10);
		
		JLabel lblPin = new JLabel("Pin:");
		lblPin.setBounds(70, 46, 23, 16);
		frmPinGenerator.getContentPane().add(lblPin);

		txtPin = new JTextField();
		txtPin.setBackground(SystemColor.window);
		txtPin.setEditable(false);
		txtPin.setBounds(95, 40, 134, 28);
		txtPin.setBorder(javax.swing.BorderFactory.createEmptyBorder());
		frmPinGenerator.getContentPane().add(txtPin);
		txtPin.setColumns(10);
		
		btnSaveSecret = new JButton("");
		btnSaveSecret.setBorder(javax.swing.BorderFactory.createEmptyBorder());
		btnSaveSecret.setIcon(new ImageIcon(MainGui.class.getResource("/net/jingx/icons/disk.png")));
		btnSaveSecret.setBounds(227, 7, 29, 29);
		btnSaveSecret.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String secret = new String(txtSecretKey.getPassword());
				if(secret!=null && !secret.equals("")){
					saveSecret(secret);	
				}
			}
		});
		frmPinGenerator.getContentPane().add(btnSaveSecret);
		
		lblTimersec = new JLabel("");
		lblTimersec.setBounds(237, 46, 43, 16);
		frmPinGenerator.getContentPane().add(lblTimersec);
		
		timerNextKey = new TimerNextKey(lblTimersec, makeTimerAction());
		if(secret!=null){
			txtSecretKey.setText(secret);
			timerNextKey.start();
		}
		generateAndDisplayPin();
		frmPinGenerator.addWindowFocusListener(new WindowAdapter() {
		    public void windowGainedFocus(WindowEvent e) {
		    	txtPin.requestFocusInWindow();
		    }
		});

	}
	
	private String readSecret(){
		try{
			String secret = null;
			File fSec = new File(PATH_GAUTH_SECKEY + SEC_FILENAME);
			if(fSec.exists()){
				 FileReader fr = new FileReader(fSec);
				 BufferedReader br = new BufferedReader(fr);
				 secret = br.readLine();
				 br.close();
			}
			return secret;
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	private void saveSecret(String secret){
		try{
			File fDirGAuth = new File(PATH_GAUTH_SECKEY);
			fDirGAuth.mkdirs();
			FileWriter fw = new FileWriter(PATH_GAUTH_SECKEY + SEC_FILENAME);
			fw.write(secret);
			fw.flush();
			fw.close();
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public void doSetVisible() {
		frmPinGenerator.setVisible(true);
	}
	
	private ActionListener makeTimerAction() {
		ActionListener a = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				generateAndDisplayPin();
			}
		};
		return a;
	}
		
	private void generateAndDisplayPin(){
		String secret = new String(txtSecretKey.getPassword());
		if(secret!=null && !secret.equals("")){
			if(secret.length() < MIN_KEY_BYTES){
				txtPin.setText("Key is too short");
				if(timerNextKey.isRunning()){
					timerNextKey.stop();
				}
			}else{
				txtPin.setText(Main.computePin(secret, null));
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.12880334402644114, 'fraction_numerical': 0.013414989792942549, 'mean_word_length': 4.300360638845956, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '645350', 'n_tokens_mistral': 3959, 'n_tokens_neox': 3332, 'n_words': 653}