diff --git a/bondoman/app/build.gradle.kts b/bondoman/app/build.gradle.kts index 295da236dfe95d661b3d181cb2137ce5baa53654..e2cfe0e1e21d98419695a17e643cbef45da6693c 100644 --- a/bondoman/app/build.gradle.kts +++ b/bondoman/app/build.gradle.kts @@ -51,4 +51,5 @@ dependencies { androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") implementation("com.squareup.retrofit2:retrofit:2.9.0") implementation("com.squareup.retrofit2:converter-gson:2.9.0") + implementation("androidx.security:security-crypto:1.0.0") } \ No newline at end of file diff --git a/bondoman/app/src/main/java/com/example/bondoman/LoginPage.kt b/bondoman/app/src/main/java/com/example/bondoman/LoginPage.kt index be5565dc3482735faaac1e76f5b385ef51c95efb..05a6ddf64ae9fc6099faac884e279922e7f60ac0 100644 --- a/bondoman/app/src/main/java/com/example/bondoman/LoginPage.kt +++ b/bondoman/app/src/main/java/com/example/bondoman/LoginPage.kt @@ -47,6 +47,7 @@ class LoginPage : AppCompatActivity() { if(dataLogin != null) { val token = dataLogin.token + Log.d("Login", token) AuthManager.saveToken(this@LoginPage, token) val toMain = Intent(this@LoginPage, MainActivity::class.java) startActivity(toMain) diff --git a/bondoman/app/src/main/java/com/example/bondoman/utils/AuthManager.kt b/bondoman/app/src/main/java/com/example/bondoman/utils/AuthManager.kt index 0ae0c83cc83cd6136fc52fc091fffc3b418f9e49..d0f0c69106c586d51e61c9da7b07a1337361b227 100644 --- a/bondoman/app/src/main/java/com/example/bondoman/utils/AuthManager.kt +++ b/bondoman/app/src/main/java/com/example/bondoman/utils/AuthManager.kt @@ -1,28 +1,40 @@ package com.example.bondoman.utils import android.content.Context +import android.content.SharedPreferences +import androidx.security.crypto.EncryptedSharedPreferences +import androidx.security.crypto.MasterKeys object AuthManager { private const val PREFS_NAME = "MyPreferences" private const val TOKEN_KEY = "token" + fun getSharedPreferences(context: Context): SharedPreferences { + val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC) + return EncryptedSharedPreferences.create( + PREFS_NAME, masterKeyAlias, context, + EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, + EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM + ) + } + fun saveToken(context: Context, token: String){ - val sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + val sharedPreferences = getSharedPreferences(context) val editor = sharedPreferences.edit() editor.putString(TOKEN_KEY, token) editor.apply() } fun getToken(context: Context): String? { - val sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + val sharedPreferences = getSharedPreferences(context) return sharedPreferences.getString(TOKEN_KEY, null) } fun deleteToken(context: Context) { - val sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + val sharedPreferences = getSharedPreferences(context) val editor = sharedPreferences.edit() editor.remove(TOKEN_KEY) editor.apply() } -} \ No newline at end of file +} diff --git a/bondoman/app/src/main/res/layout/activity_login_page.xml b/bondoman/app/src/main/res/layout/activity_login_page.xml index 73e3bb25bdec193e76c21d5e28eb056d87cc4afc..12cea6b3ec7ca3ffde09d758180820d7fa30bf08 100644 --- a/bondoman/app/src/main/res/layout/activity_login_page.xml +++ b/bondoman/app/src/main/res/layout/activity_login_page.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" @@ -14,10 +14,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" - android:layout_marginTop="80dp" + android:layout_marginTop="130dp" android:text="MLEBU" android:textSize="32dp" - android:textStyle="bold" /> + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/img_login" @@ -25,8 +28,10 @@ android:layout_height="wrap_content" android:layout_below="@id/txt1_login" android:layout_centerHorizontal="true" - android:layout_marginStart="10dp" - android:src="@drawable/login_logo" /> + android:src="@drawable/login_logo" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/txt1_login" /> <TextView android:id="@+id/txt2_login" @@ -36,69 +41,75 @@ android:layout_centerHorizontal="true" android:fontFamily="@font/font_parisienne" android:text="Sugeng Rawuh" - android:textSize="24dp" /> + android:textSize="24dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/img_login" /> + <TextView android:id="@+id/txt3_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/txt2_login" - android:layout_marginStart="30dp" - android:layout_marginTop="20dp" + android:layout_marginLeft="30dp" android:text="E-mail" - android:textSize="16dp" /> + android:textSize="16dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/txt2_login" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/email_field_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/txt3_login" - android:layout_marginStart="30dp" - android:layout_marginEnd="30dp" app:endIconMode="clear_text" - > + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/txt3_login"> <EditText android:id="@+id/email_field" android:layout_width="match_parent" android:layout_height="50dp" + android:layout_marginStart="30dp" + android:layout_marginEnd="30dp" android:background="@drawable/custom_field" android:paddingLeft="10dp" - android:textSize="16dp" - /> - + android:textSize="16dp" /> </com.google.android.material.textfield.TextInputLayout> - <TextView android:id="@+id/txt4_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/email_field_layout" - android:layout_marginStart="30dp" - android:layout_marginTop="20dp" + android:layout_marginLeft="30dp" android:text="Kunci" - android:textSize="16dp" /> + android:textSize="16dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/email_field_layout" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/password_field_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/txt4_login" - android:layout_marginStart="30dp" - android:layout_marginEnd="30dp" app:endIconMode="password_toggle" - > + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/txt4_login"> <EditText android:id="@+id/password_field" android:layout_width="match_parent" android:layout_height="50dp" + android:layout_marginStart="30dp" + android:layout_marginEnd="30dp" android:background="@drawable/custom_field" android:overScrollMode="ifContentScrolls" android:paddingLeft="10dp" android:textSize="16dp" /> - </com.google.android.material.textfield.TextInputLayout> @@ -108,11 +119,15 @@ android:layout_height="wrap_content" android:layout_below="@id/password_field_layout" android:layout_centerHorizontal="true" - android:layout_marginTop="30dp" android:width="150dp" android:background="@drawable/custom_button" android:text="Mlebu" android:textColor="@color/white" - android:textSize="16dp" /> + android:textSize="16dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/password_field_layout" /> + -</RelativeLayout> \ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file