stable1
This commit is contained in:
parent
c7df29ffa5
commit
7836bbd92d
@ -11,16 +11,6 @@
|
||||
<entry key="..\:/Android Projects/TaskListA2/app/src/main/res/layout/item_task.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/Android Projects/TaskListA2/app/src/main/res/layout/main_activity.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/Android Projects/TaskListA2/app/src/main/res/layout/main_fragment.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/Android Projects/TaskListA3/app/src/main/res/layout/fragment_change_pass.xml" value="0.2109375" />
|
||||
<entry key="..\:/Android Projects/TaskListA3/app/src/main/res/layout/fragment_login_page.xml" value="0.2109375" />
|
||||
<entry key="..\:/Android Projects/TaskListA3/app/src/main/res/layout/fragment_set_pass.xml" value="0.2109375" />
|
||||
<entry key="..\:/Android Projects/TaskListA3/app/src/main/res/layout/fragment_task_list.xml" value="0.2210144927536232" />
|
||||
<entry key="..\:/Android Projects/TaskListA3/app/src/main/res/layout/item_task.xml" value="0.2210144927536232" />
|
||||
<entry key="..\:/Android Projects/TaskListA5/app/src/main/res/layout/fragment_items.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/Android Projects/TaskListA5/app/src/main/res/layout/fragment_login_page.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/Android Projects/TaskListA5/app/src/main/res/layout/fragment_task_list.xml" value="0.2210144927536232" />
|
||||
<entry key="..\:/Android Projects/TaskListA5/app/src/main/res/layout/item_task.xml" value="0.2210144927536232" />
|
||||
<entry key="..\:/Android Projects/TaskListA5/app/src/main/res/layout/items.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/AndroidStudio/TaskListA/app/src/main/res/drawable/bordershape.xml" value="0.22135416666666666" />
|
||||
<entry key="..\:/AndroidStudio/TaskListA/app/src/main/res/layout/activity_login_page.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/AndroidStudio/TaskListA/app/src/main/res/layout/fragment_activity_login_page.xml" value="0.2682291666666667" />
|
||||
@ -31,6 +21,7 @@
|
||||
<entry key="..\:/AndroidStudio/TaskListA/app/src/main/res/layout/item_task.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/AndroidStudio/TaskListA/app/src/main/res/layout/main_activity.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/AndroidStudio/TaskListA/app/src/main/res/layout/main_fragment.xml" value="0.20520833333333333" />
|
||||
<entry key="..\:/Users/Maksio/StudioProjects/TaskListA/app/src/main/res/layout/item_task.xml" value="0.21770833333333334" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
|
@ -4,6 +4,8 @@ import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import java.util.*
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
@ -19,8 +21,14 @@ private object AES256{
|
||||
private val encorder = Base64.getEncoder()
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private val decorder = Base64.getDecoder()
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun cipher(opmode:Int): Cipher {
|
||||
val secretKey = "H+MbQeThWmZq4t7w!z%C&F)J@NcRfUjX"
|
||||
// val keygen = KeyGenerator.getInstance("AES")
|
||||
// keygen.init(256)
|
||||
// val key: SecretKey = keygen.generateKey()
|
||||
// val secretKey = key.toString()
|
||||
|
||||
if(secretKey.length != 32) throw RuntimeException("SecretKey length is not 32 chars")
|
||||
val c = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||
val sk = SecretKeySpec(secretKey.toByteArray(Charsets.UTF_8), "AES")
|
||||
|
@ -48,24 +48,32 @@ class ChangePass : Fragment(){
|
||||
requireActivity().getSharedPreferences("sharedPref", Context.MODE_PRIVATE)
|
||||
val sharedPass = sharedPreference.getString("STRING_KEY", null)
|
||||
val oldPass = hash.hashString(binding.passwordOld.text.toString())
|
||||
var newPass = binding.passwordNew.text.toString()
|
||||
val newPass = binding.passwordNew.text.toString()
|
||||
val newPassHash = hash.hashString(newPass)
|
||||
|
||||
if(oldPass.equals(sharedPass,false)) {
|
||||
if (newPass.length >= 4){
|
||||
newPass = hash.hashString(newPass)
|
||||
savePass(newPass)
|
||||
Toast.makeText(requireActivity(),"Password updated!",Toast.LENGTH_SHORT).show()
|
||||
findNavController().navigate(R.id.action_changePass_to_taskListFragment)
|
||||
}
|
||||
else{
|
||||
Toast.makeText(requireActivity(),"Password too short,it should have at least 4 characters!",Toast.LENGTH_SHORT).show()
|
||||
findNavController().navigate(R.id.action_changePass_self)
|
||||
when {
|
||||
newPassHash.equals(sharedPass,false) -> {
|
||||
Toast.makeText( requireActivity(),
|
||||
"Password cannot be similar to the previous password!",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
//findNavController().navigate(R.id.action_changePass_self)
|
||||
}
|
||||
newPass.length >= 4 -> {
|
||||
savePass(newPassHash)
|
||||
Toast.makeText(requireActivity(),"Password updated!",Toast.LENGTH_SHORT).show()
|
||||
findNavController().navigate(R.id.action_changePass_to_taskListFragment)
|
||||
}
|
||||
else -> {
|
||||
Toast.makeText(requireActivity(),"Password too short,it should have at least 4 characters!",Toast.LENGTH_SHORT).show()
|
||||
//findNavController().navigate(R.id.action_changePass_self)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
Toast.makeText(requireActivity(),"Password is incorrect, try again!",Toast.LENGTH_SHORT).show()
|
||||
findNavController().navigate(R.id.action_changePass_self)
|
||||
//findNavController().navigate(R.id.action_changePass_self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.example.tasklist.ui.adapters
|
||||
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.tasklist.ChCrypto
|
||||
import com.example.tasklist.R
|
||||
import com.example.tasklist.data.Task
|
||||
import com.example.tasklist.databinding.ItemTaskBinding
|
||||
@ -49,7 +52,12 @@ class TaskAdapter internal constructor(
|
||||
}
|
||||
|
||||
interface TaskItemClickListener {
|
||||
fun chooseTask(task: Task)
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun chooseTask(task: Task): String {
|
||||
val crypting = ChCrypto
|
||||
val taskCrypred = crypting.aesDecrypt(task.name)
|
||||
return taskCrypred
|
||||
}
|
||||
}
|
||||
|
||||
private class TaskDiffCallback : DiffUtil.ItemCallback<Task> () {
|
||||
|
@ -65,23 +65,15 @@ class TaskListFragment : Fragment(), TaskItemClickListener {
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun chooseTask(task: Task) {
|
||||
override fun chooseTask(task: Task): String {
|
||||
val crypting = ChCrypto
|
||||
val taskCrypred = crypting.aesDecrypt(task.name)
|
||||
val taskToast = Toast.makeText(activity, "Zostało wybrane zadanie $taskCrypred", Toast.LENGTH_LONG)
|
||||
taskToast.show()
|
||||
// val taskToast = Toast.makeText(activity, "Zostało wybrane zadanie $taskCrypred", Toast.LENGTH_LONG)
|
||||
// taskToast.show()
|
||||
return taskCrypred
|
||||
// val taskToast = Toast.makeText(activity, "Zostało wybrane zadanie ${task.name}", Toast.LENGTH_LONG)
|
||||
}
|
||||
|
||||
@SuppressLint("ShowToast")
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun decryptTasks(task: Task): String {
|
||||
val crypting = ChCrypto
|
||||
val taskDeCrypred = crypting.aesDecrypt(task.name)
|
||||
val taskToast = Toast.makeText(activity,taskDeCrypred, Toast.LENGTH_LONG)
|
||||
taskToast.show()
|
||||
return taskDeCrypred
|
||||
}
|
||||
|
||||
fun addTask(){
|
||||
findNavController().navigate(R.id.action_taskListFragment_to_adding_tasks)
|
||||
|
@ -30,7 +30,7 @@
|
||||
android:id="@+id/checkBox_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text='@{tlf.decryptTasks(task) + "\n" + task.date}'
|
||||
android:text='@{clickListener.chooseTask(task) + "\n" + task.date}'
|
||||
android:onClick="@{() -> clickListener.chooseTask(task)}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
Loading…
Reference in New Issue
Block a user