Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from coderbunker/issue#5-otp_new
Browse files Browse the repository at this point in the history
TOTP done
  • Loading branch information
julianschmuckli authored Aug 7, 2018
2 parents 6f00903 + 26a7aa7 commit 258a751
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 109 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@


<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleTask"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
android:stateNotNeeded="true"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".KioskActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity android:name=".SettingsActivity"></activity>
<activity
android:name=".SettingsActivity"
android:screenOrientation="landscape" />
</application>

</manifest>
86 changes: 58 additions & 28 deletions app/src/main/java/com/coderbunker/kioskapp/KioskActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
Expand All @@ -13,6 +15,9 @@
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;

import com.coderbunker.kioskapp.lib.TOTP;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -24,9 +29,9 @@
public class KioskActivity extends Activity {

private final Context context = this;
private WebView webView;
private WebView webView;
private static String password = "1234";
private static String URL = "https://naibaben.github.io/";
private static String URL = "";

private final List blockedKeys = new ArrayList(Arrays.asList(KeyEvent.KEYCODE_VOLUME_DOWN,
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_HOME, KeyEvent.KEYCODE_POWER, KeyEvent.KEYCODE_APP_SWITCH));
Expand All @@ -35,17 +40,19 @@ public class KioskActivity extends Activity {
private boolean locked = false;
private Dialog dialog;

private Button b1, b2, b3, b4;
private Button b1, b2, b3, b4, b5, b6;
private Button n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
private ArrayList<Button> numbers;

private int cptPwd;

private Timer timerLock, timerNav;

private SharedPreferences prefs;

@Override
public void onBackPressed() {
//Do nothing...
//Do nothing...
}

@Override
Expand All @@ -65,19 +72,25 @@ protected void onCreate(Bundle savedInstanceState) {

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

prefs = this.getSharedPreferences(
"com.coderbunker.kioskapp", Context.MODE_PRIVATE);

URL = prefs.getString("url", "https://naibaben.github.io/");

//Get the webView and load the URL
webView = findViewById(R.id.webview);
webView.setWebViewClient(new KioskWebviewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(URL);
Toast.makeText(this, "Loading " + URL, Toast.LENGTH_SHORT).show();

webView.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
hideSystemUI();

if(!dialogPrompted && locked) {
if (!dialogPrompted && locked) {
askPassword();
return true;
} else
Expand Down Expand Up @@ -133,26 +146,18 @@ private void hideNavBar(View view) {
}




@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}else{
} else {
hideSystemUI();
}
}


public static void setPassword(String newPwd)
{
password = newPwd;
}

public static void setURL(String newURL)
{
public static void setURL(String newURL) {
URL = newURL;
}

Expand All @@ -171,33 +176,54 @@ public void enterNumber(String number) {
case 3:
b4.setText(number);
break;
case 4:
b5.setText(number);
break;
case 5:
b6.setText(number);
break;
}

if (cptPwd == 3) {
if (cptPwd == 5) {
cptPwd = 0;
checkPwd();
} else
cptPwd++;

}

private void checkPwd() {
String pwd = b1.getText().toString() + b2.getText().toString() + b3.getText().toString() + b4.getText().toString();
if (password.equals(pwd)) {
finish();
private void launchHome() {
Intent intent = new Intent(KioskActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}

private void checkPwd() {
String otp = prefs.getString("otp", null);
if (otp == null) {
Toast.makeText(context, "Please go to the settings and create a password", Toast.LENGTH_SHORT).show();
launchHome();
} else {
dialog.dismiss();
dialogPrompted = false;
String pwd = b1.getText().toString() + b2.getText().toString() + b3.getText().toString() + b4.getText().toString() + b5.getText().toString() + b6.getText().toString();
String generated_number = TOTP.generateCurrentNumber(otp, System.currentTimeMillis());
String previous_generated_number = TOTP.generateCurrentNumber(otp, System.currentTimeMillis() - 30000);

if (pwd.equals(generated_number) || pwd.equals(previous_generated_number)) {
Toast.makeText(context, "PIN correct", Toast.LENGTH_SHORT).show();
launchHome();
} else {
dialog.dismiss();
dialogPrompted = false;
Toast.makeText(context, "Wrong PIN", Toast.LENGTH_SHORT).show();
}
}

cptPwd = 0;
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {


if (blockedKeys.contains(event.getKeyCode())) {
return true;
} else {
Expand All @@ -207,14 +233,15 @@ public boolean dispatchKeyEvent(KeyEvent event) {

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(blockedKeys.contains(event.getKeyCode())){
return true;
Toast.makeText(context, "Clicked", Toast.LENGTH_SHORT).show();
if (blockedKeys.contains(event.getKeyCode())) {
Toast.makeText(context, "Blocked", Toast.LENGTH_SHORT).show();
return false;
}
return super.onKeyDown(keyCode, event);
}

private void askPassword()
{
private void askPassword() {
dialogPrompted = true;

dialog = new Dialog(webView.getContext());
Expand All @@ -235,6 +262,9 @@ public void onDismiss(DialogInterface dialogInterface) {
b2 = dialog.findViewById(R.id.b2);
b3 = dialog.findViewById(R.id.b3);
b4 = dialog.findViewById(R.id.b4);
b5 = dialog.findViewById(R.id.b5);
b6 = dialog.findViewById(R.id.b6);


n0 = dialog.findViewById(R.id.number0);
n1 = dialog.findViewById(R.id.number1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

class KioskWebviewClient extends WebViewClient {

private String URL = "https://naibaben.github.io/";

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

if(url.contains(url)) {
if (url.contains(url)) {
view.loadUrl(url);
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/coderbunker/kioskapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

kioskmode = (Button) findViewById(R.id.button_kioskmode);
settings = (Button) findViewById(R.id.button_settings);
kioskmode = findViewById(R.id.button_kioskmode);
settings = findViewById(R.id.button_settings);

kioskmode.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Loading

0 comments on commit 258a751

Please sign in to comment.