فهرست منبع

Worked on generate password Ui, remove cancel and use buttons, password length will be 18..50 and some color changes

Khubaib 1 هفته پیش
والد
کامیت
d87c2a071e

+ 52 - 49
app/src/main/java/com/fastest/pass/account/presentation/ui/components/AccountScreen.kt

@@ -510,9 +510,9 @@ fun ColumnScope.OpenModalBottomSheetAS(
     var isSheetOpen by remember { mutableStateOf(true) }
     var passwordStrength by remember { mutableStateOf("Average") }
     var selectedSliderType by remember { mutableStateOf(sliderPasswordTypeList[0]) }
-    var sliderPosition by remember { mutableFloatStateOf(8F) }
-    var updatedColor by remember { mutableStateOf((R.color.light_yellow)) }
-    var updatedTextColor by remember { mutableStateOf((R.color.brown_text)) }
+    var sliderPosition by remember { mutableFloatStateOf(18F) }
+    var updatedColor by remember { mutableStateOf((R.color.gray_text)) }
+    var updatedTextColor by remember { mutableStateOf((R.color.gray_text)) }
 
     var isLowerCaseEnabled by remember { mutableStateOf(true) }
     var isUpperCaseEnabled by remember { mutableStateOf(false) }
@@ -550,7 +550,10 @@ fun ColumnScope.OpenModalBottomSheetAS(
                     modifier = Modifier
                         .fillMaxWidth()
                         .height(150.dp)
-                        .background(colorResource(id = updatedColor))
+                        .background(colorResource(id = updatedColor).copy(
+                            alpha = 0.2f
+                        ))
+
                 ) {
                     Column(
                         modifier = Modifier
@@ -562,7 +565,7 @@ fun ColumnScope.OpenModalBottomSheetAS(
                         Text(
                             generatedPassword,
                             style = MaterialTheme.typography.displayLarge.copy(
-                                color = colorResource(id = R.color.gray_splash)
+                                color = colorResource(id = updatedTextColor)
                             ),
                             maxLines = 2,
                             overflow = TextOverflow.Ellipsis,
@@ -598,7 +601,7 @@ fun ColumnScope.OpenModalBottomSheetAS(
                                     contentDescription = "Reset Logo",
                                     modifier = Modifier
                                         .size(24.dp, 24.dp),
-                                    tint = colorResource(id = R.color.gray_splash)
+                                    tint = colorResource(id = updatedTextColor)
                                 )
                             }
                             Spacer(modifier = Modifier.width(10.dp))
@@ -613,7 +616,7 @@ fun ColumnScope.OpenModalBottomSheetAS(
                                     contentDescription = "Copy Logo",
                                     modifier = Modifier
                                         .size(24.dp, 24.dp),
-                                    tint = colorResource(id = R.color.gray_splash)
+                                    tint = colorResource(id = updatedTextColor)
                                 )
                             }
                         }
@@ -649,25 +652,25 @@ fun ColumnScope.OpenModalBottomSheetAS(
                             },
                             onValueChangeFinished = {
                                 Log.d("slider", "Finish => ${sliderPosition.roundToInt()}")
-                                if (sliderPosition.roundToInt() == 8) {
+                                if (sliderPosition.roundToInt() <= 25) {
                                     passwordStrength = "Average"
-                                    updatedColor = R.color.light_yellow
-                                    updatedTextColor = R.color.brown_text
+                                    updatedColor = R.color.gray_text
+                                    updatedTextColor = R.color.gray_text
                                 }
-                                else if (sliderPosition.roundToInt() == 9 || sliderPosition.roundToInt() == 10) {
+                                else if (sliderPosition.roundToInt() <= 40) {
                                     passwordStrength = "Strong"
-                                    updatedColor = R.color.light_green
-                                    updatedTextColor = R.color.green_text
+                                    updatedColor = R.color.radio_button_blue
+                                    updatedTextColor = R.color.radio_button_blue
                                 }
                                 else {
                                     passwordStrength = "Very strong"
-                                    updatedColor = R.color.light_green
+                                    updatedColor = R.color.green_text
                                     updatedTextColor = R.color.green_text
                                 }
 
                                 generatedPassword = generatePassword(selectedSliderType, isLowerCaseEnabled, isUpperCaseEnabled, isNumberEnabled, isRandomSymbolsEnabled, sliderPosition.roundToInt())
                             },
-                            valueRange = 8f..128f,
+                            valueRange = 18f..50f,
                             colors = SliderDefaults.colors(
                                 thumbColor = colorResource(id = R.color.sky_green),
                                 activeTrackColor = colorResource(id = R.color.sky_green),
@@ -859,40 +862,40 @@ fun ColumnScope.OpenModalBottomSheetAS(
                             }
                         )
 
-                        Spacer(modifier = Modifier.height(5.dp))
-                        Row(
-                            modifier = Modifier
-                                .fillMaxWidth()
-                                .background(Color.Transparent),
-                            horizontalArrangement = Arrangement.End
-                        ) {
-                            TextButton(onClick = {
-                                isSheetOpen = false
-                                isSheetOpened.invoke()
-                            }) {
-                                Text(
-                                    text = "CANCEL",
-                                    style = MaterialTheme.typography.bodyMedium.copy(
-                                        textAlign = TextAlign.End
-                                    ),
-                                    color = colorResource(id = R.color.blue_text),
-                                    modifier = Modifier
-                                )
-                            }
-                            TextButton(onClick = {
-                                isSheetOpen = false
-                                isSheetOpened.invoke()
-                            }) {
-                                Text(
-                                    text = "USE",
-                                    style = MaterialTheme.typography.bodyMedium.copy(
-                                        textAlign = TextAlign.End
-                                    ),
-                                    color = colorResource(id = R.color.blue_text),
-                                    modifier = Modifier
-                                )
-                            }
-                        }
+//                        Spacer(modifier = Modifier.height(5.dp))
+//                        Row(
+//                            modifier = Modifier
+//                                .fillMaxWidth()
+//                                .background(Color.Transparent),
+//                            horizontalArrangement = Arrangement.End
+//                        ) {
+//                            TextButton(onClick = {
+//                                isSheetOpen = false
+//                                isSheetOpened.invoke()
+//                            }) {
+//                                Text(
+//                                    text = "CANCEL",
+//                                    style = MaterialTheme.typography.bodyMedium.copy(
+//                                        textAlign = TextAlign.End
+//                                    ),
+//                                    color = colorResource(id = R.color.blue_text),
+//                                    modifier = Modifier
+//                                )
+//                            }
+//                            TextButton(onClick = {
+//                                isSheetOpen = false
+//                                isSheetOpened.invoke()
+//                            }) {
+//                                Text(
+//                                    text = "USE",
+//                                    style = MaterialTheme.typography.bodyMedium.copy(
+//                                        textAlign = TextAlign.End
+//                                    ),
+//                                    color = colorResource(id = R.color.blue_text),
+//                                    modifier = Modifier
+//                                )
+//                            }
+//                        }
 
                     }
                 }

+ 11 - 8
app/src/main/java/com/fastest/pass/app/Utils.kt

@@ -29,11 +29,7 @@ class Utils {
             return keyGen.generateKey()
         }
 
-        fun encryptData(
-            data: String,
-            secretKeyString: String,
-            ivString: String,
-        ) : String {
+        fun encryptData(data: String, secretKeyString: String, ivString: String, ) : String {
             val ivKey: IvParameterSpec = IvParameterSpec(ivString.toByteArray(Charsets.UTF_8))
             val secKey: SecretKey = SecretKeySpec(secretKeyString.toByteArray(Charsets.UTF_8), "AES")
 
@@ -43,7 +39,6 @@ class Utils {
 
             val ivBase64 = Base64.encodeToString(ivString.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
             val encryptedDataBase64 = Base64.encodeToString(encryptedData, Base64.DEFAULT)
-
             return encryptedDataBase64
         }
 
@@ -58,7 +53,6 @@ class Utils {
 
             val decryptedData = cipher.doFinal(encryptedBytes)
             val decryptedString = String(decryptedData, Charsets.UTF_8)
-
             return decryptedString
         }
 
@@ -67,7 +61,16 @@ class Utils {
             val email = userinfo.email
             val saltKey = "${id}_${email}_${id}"
             val filterSaltKey = saltKey.replace("[@.]".toRegex(), "")
-            return filterSaltKey
+            val encodedSaltKey = Base64.encodeToString(filterSaltKey.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
+            val salt16Length = encodedSaltKey.take(16)
+            return salt16Length
+        }
+
+        fun customPassword(password: String) : String {
+            val reversedPassword = "$password${password.reversed()}"
+            val encodedPassword = Base64.encodeToString(reversedPassword.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
+            val password16Length = encodedPassword.take(16)
+            return password16Length
         }
     }
 }

+ 1 - 8
app/src/main/java/com/fastest/pass/home/presentation/ui/fragment/HomeFragment.kt

@@ -1,6 +1,7 @@
 package com.fastest.pass.home.presentation.ui.fragment
 
 import android.os.Bundle
+import android.util.Base64
 import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
@@ -58,14 +59,6 @@ class HomeFragment : BaseFragment() {
                                 .background(colorResource(id = R.color.home_background_color))
                                 .padding(paddingValues.calculateBottomPadding())
                         ) {
-
-//                            val saltKey = basePreferenceHelper.getCustomSaltKey()
-//                            val userPassword = basePreferenceHelper.getPassword()
-//
-//                            val passwords_title_enc = Utils.encryptData(
-//                                "khubaibparacha", "userPassword" ?: "", saltKey ?: "")
-//                            Log.d("saltKey", "saltKey = $saltKey, password = $userPassword, passwords_title_enc = $passwords_title_enc")
-
                             HomeScreen { clickType ->
                                 when (clickType) {
                                     ClickType.GOTO_ADD_NEW_ITEMS -> {