Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
First upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Nibot1 committed Sep 22, 2016
1 parent 0449043 commit 678ef0f
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Passwort</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Binary file added bin/GUI/Apps-password-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/GUI/Apps-password-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/GUI/lengthJInputdialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package GUI;

import java.text.ParseException;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class lengthJInputdialog {
private static int lenght;
private static String lenghtString;
private static final int maxSize = 59;
Icon icon = new ImageIcon(GUI.lengthJInputdialog.class.getResource("Apps-password-icon.png"));

public int setLength() throws ParseException {
lenghtString = (String) JOptionPane.showInputDialog(null,
"Wie viele Zeichen soll dein Passwort haben ? (max. 58) ", "Passwort", JOptionPane.QUESTION_MESSAGE,
icon, null, null);
if (lenghtString == null) {
System.exit(0);
} else {
try {
lenght = Integer.parseInt(lenghtString);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, lenghtString +" ist keine Zahl", "Error!!!",
JOptionPane.WARNING_MESSAGE, null);
System.exit(0);
}
if (lenght >= maxSize) {
JOptionPane.showMessageDialog(null, "Diese Zahl ist zu hoch!!!", "Error!!!",
JOptionPane.WARNING_MESSAGE, null);
System.exit(0);
}
}
return lenght;

}

public int getLenght() {
return lenght;
}
}
50 changes: 50 additions & 0 deletions src/GUI/passwordJMessageBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package GUI;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.text.ParseException;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class passwordJMessageBox {
final JFileChooser fc = new JFileChooser();
Icon icon = new ImageIcon(GUI.lengthJInputdialog.class.getResource("Apps-password-icon.png"));
int dialogButton = JOptionPane.YES_NO_OPTION;
public String setPassword() throws ParseException{
GUI.lengthJInputdialog input = new lengthJInputdialog();
input.setLength();
final int length = input.getLenght();
//System.out.println(length);
final String pass = Main.Passwort.createPassword(length);
//System.out.println(pass);
return pass;}
public void showPassword() throws Exception{
final String password = setPassword();
JOptionPane.showMessageDialog(null, "Dein Passwort ist : \n"+ password, "Passwort",
JOptionPane.YES_NO_OPTION, icon);
int dialogResult = JOptionPane.showConfirmDialog (null, "Willst du das Passwort Speichern ?","Speichern ?",dialogButton);
if(dialogResult == JOptionPane.YES_OPTION){

JFrame frame = new JFrame("Datei Öffnen");
frame .setVisible(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JFileChooser saveFile = new JFileChooser();
int saveOption = saveFile.showSaveDialog(frame);
if(saveOption == JFileChooser.APPROVE_OPTION){
String konto = (String) JOptionPane.showInputDialog(null, "Zu welchem Konto gehört das Passwort ?",
"Passwort", JOptionPane.QUESTION_MESSAGE, icon, null, null);

try{
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(saveFile.getSelectedFile().getPath(),/*append*/ true));
fileWriter.append(konto+": " + password+"\n");
fileWriter.close();
}catch(Exception ex){

}

}}}}
94 changes: 94 additions & 0 deletions src/GUI/passwortAbfage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package GUI;

import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.LayoutManager;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;

public class passwortAbfage {
public void initialize() throws IOException {
Icon icon = new ImageIcon(GUI.lengthJInputdialog.class.getResource("Apps-password-icon.png"));
LayoutManager lm = new BorderLayout();
//Image imc = (Image) icon;
JFrame f = new JFrame("Passwort");
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//f.setIconImage(imc);
f.setAlwaysOnTop(true);
f.setAutoRequestFocus(true);
f.setSize(300, 200);
f.setLayout(lm);
JPasswordField pwf = new JPasswordField();
pwf.setEditable(true);
pwf.setVisible(true);
JLabel label = new JLabel();
label.setText("Gib dein Passwort ein");
File trys = new File("text.txt");

BufferedWriter fileWriter = new BufferedWriter(new FileWriter(trys));
fileWriter.write("0");
if(!trys.exists()){
fileWriter.write("0");
}
label.setVisible(true);
FileReader fr = new FileReader(trys);
BufferedReader br = new BufferedReader(fr);
String passwortVersuche = br.readLine();
if(Integer.parseInt(passwortVersuche) > 4){
JOptionPane.showMessageDialog(f, "Kontaktiere Tobin um dein Passwort Zurückzusetzen");
System.exit(0);
}
String text = "Das Passwort ist";
String eingabe = "";
File passwort = new File("passwort.txt");
int i = 1;
while(!passwort.exists()&&(i==1 )){
f.add(pwf,"Center");
label.setText("Gib ein neues passwort ein:");
f.add(label,"North");
String passwort1 = String.valueOf(pwf.getPassword());
label.setText("Nochmal");
String passwort2 = String.valueOf(pwf.getPassword());
if(passwort1 ==passwort2){
BufferedWriter fileWriterpassword = new BufferedWriter(new FileWriter("passwort.txt"));
if(!trys.exists()){
fileWriter.write(passwort1);
}
i = 0;
f.remove(label);
f.remove(pwf);
label.setText("");
}
}
f.add(pwf, "Center");
label.setText("Gib dein Passwort ein du hast noch "+(3- Integer.parseInt(passwortVersuche)+" Versuche"));
f.add(label, "North");
try{
eingabe = String.valueOf(pwf.getPassword());
}catch(Exception x){
x.printStackTrace();
}FileReader frp = new FileReader("passwort.txt");
BufferedReader brp = new BufferedReader(fr);
String passwortfile = br.readLine();
if(!eingabe.equals(passwortfile)){

int paswortInt = Integer.parseInt(passwortVersuche) +1;
fileWriter.write(paswortInt);
System.exit(0);
}

}

}
33 changes: 33 additions & 0 deletions src/Main/Passwort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package Main;

import java.io.IOException;
import java.security.SecureRandom;

import GUI.passwordJMessageBox;
import GUI.passwortAbfage;

public class Passwort {

// private static final int length;

public static String createPassword(int length) {
final String allowedChars = "0123456789abcdefghijklmnopqrstuvwABCDEFGHIJKLMNOP!§$%&?*+#";
SecureRandom random = new SecureRandom();
StringBuilder pass = new StringBuilder(length);
for (int i = 0; i < length; i++) {
pass.append(allowedChars.charAt(random.nextInt(allowedChars.length())));
//System.out.println(pass.toString());

}
return pass.toString();}

public static void main(String[] args) throws Exception {
//GUI.passwortAbfage passwort = new passwortAbfage();
//passwort.initialize();
GUI.passwordJMessageBox output = new passwordJMessageBox();
output.showPassword();
System.exit(0);

}

}

0 comments on commit 678ef0f

Please sign in to comment.