Compare commits
12
Commits
017e5c06ce
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfb91a2860 | ||
|
|
fd0f504a9c | ||
|
|
8d246f3944 | ||
|
|
249ee6fe65 | ||
|
|
6a02be9f2e | ||
|
|
763948e288 | ||
|
|
70a2ddec87 | ||
|
|
037e4e3c6f | ||
|
|
50675e0bbd | ||
|
|
d9c4bae6a4 | ||
|
|
14f9dc5ec6 | ||
|
|
baa9e4a8ee |
No files matched your search
@@ -7,23 +7,22 @@ public class Credentials {
|
||||
|
||||
public Credentials(String login, String password) {
|
||||
this.hash = Helpers.getHash(password);
|
||||
System.out.println(hash);
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
|
||||
boolean usernameGiven = false;
|
||||
String hashData;
|
||||
|
||||
|
||||
//iterator over file
|
||||
for (String line:
|
||||
Helpers.readTextdatei("data/passwd.txt")) {
|
||||
if(login == line) {
|
||||
if(login.equals(line)) {
|
||||
usernameGiven = true;
|
||||
continue;
|
||||
}
|
||||
if(usernameGiven && hash == line) {
|
||||
if(usernameGiven && hash.equals(line)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+29
-2
@@ -1,5 +1,32 @@
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
if(login(System.in)) {
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean login(InputStream in) {
|
||||
Scanner s = new Scanner(in);
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
System.out.print("Benutzername: ");
|
||||
String login = s.next();
|
||||
System.out.print("Passwort: ");
|
||||
String passwort = s.next();
|
||||
|
||||
Credentials cred = new Credentials(login, passwort);
|
||||
|
||||
if (cred.valid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
System.out.println("Du kommst hier nicht rein");
|
||||
}
|
||||
s.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,13 @@ class CredentialsTest {
|
||||
|
||||
@Test
|
||||
void validWrongData() {
|
||||
Credentials cred = new Credentials("hofmannol", "GEHEIM123");
|
||||
Credentials cred = new Credentials("brunoklasing", "GEHEIM123");
|
||||
assertFalse(cred.valid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void validWrongData2() {
|
||||
Credentials cred = new Credentials("wimmerma", "GERONIMO");
|
||||
assertFalse(cred.valid());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MainTest {
|
||||
|
||||
@Test
|
||||
public void testFirstTryRight() {
|
||||
|
||||
//Arrange
|
||||
byte[] bytes = "hofmannol\nGERONIMO\n".getBytes();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
|
||||
|
||||
//Act
|
||||
boolean logged_in = Main.login(in);
|
||||
|
||||
assertTrue(logged_in);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user