Compare commits
20
Commits
ebe8dd0b6e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfb91a2860 | ||
|
|
fd0f504a9c | ||
|
|
8d246f3944 | ||
|
|
249ee6fe65 | ||
|
|
6a02be9f2e | ||
|
|
763948e288 | ||
|
|
70a2ddec87 | ||
|
|
037e4e3c6f | ||
|
|
50675e0bbd | ||
|
|
d9c4bae6a4 | ||
|
|
14f9dc5ec6 | ||
|
|
baa9e4a8ee | ||
|
|
017e5c06ce | ||
|
|
02d85ae57c | ||
|
|
82fa878456 | ||
|
|
021d5a34bc | ||
|
|
3d3587b101 | ||
|
|
47a7b92917 | ||
|
|
476a5b6ed1 | ||
|
|
fdb392d547 |
No files matched your search
+18
-1
@@ -1,4 +1,7 @@
|
|||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class Credentials {
|
public class Credentials {
|
||||||
|
|
||||||
private String login;
|
private String login;
|
||||||
private String hash;
|
private String hash;
|
||||||
|
|
||||||
@@ -8,10 +11,24 @@ public class Credentials {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean valid() {
|
public boolean valid() {
|
||||||
|
|
||||||
|
boolean usernameGiven = false;
|
||||||
|
|
||||||
|
|
||||||
|
//iterator over file
|
||||||
for (String line:
|
for (String line:
|
||||||
Helpers.readTextdatei("data/passwd.txt")) {
|
Helpers.readTextdatei("data/passwd.txt")) {
|
||||||
System.out.println(line);
|
if(login.equals(line)) {
|
||||||
|
usernameGiven = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(usernameGiven && hash.equals(line)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,32 @@
|
|||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,31 @@
|
|||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class CredentialsTest {
|
class CredentialsTest {
|
||||||
|
|
||||||
@org.junit.jupiter.api.Test
|
@Test
|
||||||
void valid() {
|
void existingCheck() {
|
||||||
|
Credentials cred = new Credentials("apple", "windows");
|
||||||
|
assertNotNull(cred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validData() {
|
||||||
|
Credentials cred = new Credentials("hofmannol", "GERONIMO");
|
||||||
|
assertTrue(cred.valid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validWrongData() {
|
||||||
|
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