تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
بعد تسجيل المستخدمين الدخول بنجاح، أو إنشاء حسابات، أو تغيير كلمات المرور، أو السماح
لتخزين بيانات الاعتماد الخاصة بهم لإجراء عمليات المصادقة المستقبلية بشكل آلي في تطبيقك.
أنشئ عنصر Credential يحتوي على معلومات تسجيل الدخول الخاصة بالمستخدم. بالنسبة
مثلاً، للسماح للمستخدمين بتخزين بيانات الاعتماد الخاصة بهم بعد تسجيل الدخول بنجاح باستخدام
كلمات مرورها:
بعد ذلك، يمكنك الاتصال CredentialsClient.save() لحفظ بيانات المستخدمين
بيانات الاعتماد. إذا لم يكن الاتصال برقم CredentialsClient.save() على الفور
بنجاح، فقد تكون بيانات الاعتماد جديدة، وفي هذه الحالة يجب على المستخدم تأكيد
طلب الحفظ. حلّ ResolvableApiException من خلال
startResolutionForResult() لتطلب من المستخدم التأكيد.
إذا اختار المستخدم عدم حفظ بيانات الاعتماد، لن يُطلَب منه مرة أخرى
لحفظ بيانات اعتماد أي حساب للتطبيق. في حال الاتصال
CredentialsClient.save() بعد أن يختار المستخدم إيقاف الخدمة، ستتضمّن النتيجة
رمز الحالة CANCELED. يمكن للمستخدم الموافقة لاحقًا من خلال Google
تطبيق "الإعدادات"، في قسم "Smart Lock لكلمات المرور". يجب على المستخدم تفعيل
حفظ بيانات الاعتماد لجميع الحسابات لتتم مطالبتك بحفظ بيانات الاعتماد في المرة القادمة.
mCredentialsClient.save(credential).addOnCompleteListener(newOnCompleteListener<Void>(){@OverridepublicvoidonComplete(@NonNullTask<Void>task){if(task.isSuccessful()){Log.d(TAG,"SAVE: OK");Toast.makeText(activity,"Credentials saved",Toast.LENGTH_SHORT).show();return;}Exceptione=task.getException();if(einstanceofResolvableApiException){// Try to resolve the save request. This will prompt the user if// the credential is new.ResolvableApiExceptionrae=(ResolvableApiException)e;try{rae.startResolutionForResult(this,RC_SAVE);}catch(IntentSender.SendIntentExceptionexception){// Could not resolve the requestLog.e(TAG,"Failed to send resolution.",exception);Toast.makeText(activity,"Save failed",Toast.LENGTH_SHORT).show();}}else{// Request has no resolutionToast.makeText(activity,"Save failed",Toast.LENGTH_SHORT).show();}}});</pre>
@OverridepublicvoidonActivityResult(intrequestCode,intresultCode,Intentdata){super.onActivityResult(requestCode,resultCode,data);// ...if(requestCode==RC_SAVE){if(resultCode==RESULT_OK){Log.d(TAG,"SAVE: OK");Toast.makeText(this,"Credentials saved",Toast.LENGTH_SHORT).show();}else{Log.e(TAG,"SAVE: Canceled by user");}}// ...}
عند حفظ بيانات اعتماد كلمة المرور باستخدام Smart Lock على الأجهزة التي تعمل بنظام التشغيل Android O
أو إصدار أحدث، يستخدم Smart Lock مربّع حوار تأكيد الملء التلقائي
كلما أمكن ذلك. (لاحظ أن بيانات الاعتماد التي تم حفظها باستخدام الملء التلقائي مع
تتم مشاركة Google ثنائية الاتجاه مع Smart Lock لكلمات المرور).
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eSmart Lock for Passwords is deprecated; migrate to Credential Manager for enhanced security and user experience with passkey, password, and federated identity support.\u003c/p\u003e\n"],["\u003cp\u003eStore user credentials after sign-in, account creation, or password changes to enable automated authentication in your app using Credential Manager.\u003c/p\u003e\n"],["\u003cp\u003eCreate \u003ccode\u003eCredential\u003c/code\u003e objects with user sign-in information, including email, password (securely), account type, and profile details, before saving them with \u003ccode\u003eCredentialsClient.save()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eHandle user confirmation for new credentials using \u003ccode\u003eResolvableApiException\u003c/code\u003e and \u003ccode\u003estartResolutionForResult()\u003c/code\u003e to ensure smooth credential saving.\u003c/p\u003e\n"],["\u003cp\u003eRetrieve stored credentials using \u003ccode\u003eCredentialsClient.request()\u003c/code\u003e for seamless user authentication within your app.\u003c/p\u003e\n"]]],[],null,["# Store a user's credentials\n\n| **Deprecated:** Smart Lock for Passwords is deprecated. To ensure the continued security and usability of your app, [migrate to\n| Credential Manager](https://developer.android.com/training/sign-in/passkeys/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience.\n\nAfter users successfully sign in, create accounts, or change passwords, allow\nthem to store their credentials to automate future authentication in your app.\n\nBefore you begin\n----------------\n\n[Configure an Android Studio project](/identity/smartlock-passwords/android/get-started).\n\nStore credentials\n-----------------\n\nCreate a `Credential` object containing a user's sign-in information. For\nexample, to let users store their credentials after successfully signing in with\ntheir passwords: \n\n Credential credential = new Credential.Builder(email)\n .setPassword(password) // Important: only store passwords in this field.\n // Android autofill uses this value to complete\n // sign-in forms, so repurposing this field will\n // likely cause errors.\n .build();\n\nOr, for example, after users successfully\n[sign in with their Google account](/identity/sign-in/android/people): \n\n GoogleSignInAccount gsa = signInTask.getResult();\n Credential credential = new Credential.Builder(gsa.getEmail())\n .setAccountType(IdentityProviders.GOOGLE)\n .setName(gsa.getDisplayName())\n .setProfilePictureUri(gsa.getPhotoUrl())\n .build();\n\nThen, call [`CredentialsClient.save()`](/android/reference/com/google/android/gms/auth/api/credentials/CredentialsClient#save(com.google.android.gms.auth.api.credentials.Credential)) to save users'\ncredentials. If the call to `CredentialsClient.save()` is not immediately\nsuccessful, the credentials might be new, in which case the user must confirm\nthe save request. Resolve the `ResolvableApiException` with\n`startResolutionForResult()` to prompt the user for confirmation.\n\nIf the user chooses not to save credentials, the user won't be prompted again to\nsave any account's credentials for the app. If you call\n`CredentialsClient.save()` after a user has opted out, its result will have a\nstatus code of [`CANCELED`](/android/reference/com/google/android/gms/common/api/CommonStatusCodes#CANCELED). The user can opt in later from the Google\nSettings app, in the Smart Lock for Passwords section. The user must enable\ncredential saving for all accounts to be prompted to save credentials next time. \n\n mCredentialsClient.save(credential).addOnCompleteListener(\n new OnCompleteListener\u003cVoid\u003e() {\n @Override\n public void onComplete(@NonNull Task\u003cVoid\u003e task) {\n if (task.isSuccessful()) {\n Log.d(TAG, \"SAVE: OK\");\n Toast.makeText(activity, \"Credentials saved\", Toast.LENGTH_SHORT).show();\n return;\n }\n\n Exception e = task.getException();\n if (e instanceof ResolvableApiException) {\n // Try to resolve the save request. This will prompt the user if\n // the credential is new.\n ResolvableApiException rae = (ResolvableApiException) e;\n try {\n rae.startResolutionForResult(this, RC_SAVE);\n } catch (IntentSender.SendIntentException exception) {\n // Could not resolve the request\n Log.e(TAG, \"Failed to send resolution.\", exception);\n Toast.makeText(activity, \"Save failed\", Toast.LENGTH_SHORT).show();\n }\n } else {\n // Request has no resolution\n Toast.makeText(activity, \"Save failed\", Toast.LENGTH_SHORT).show();\n }\n }\n });\u003c/pre\u003e\n\n @Override\n public void onActivityResult(int requestCode, int resultCode, Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n\n // ...\n\n if (requestCode == RC_SAVE) {\n if (resultCode == RESULT_OK) {\n Log.d(TAG, \"SAVE: OK\");\n Toast.makeText(this, \"Credentials saved\", Toast.LENGTH_SHORT).show();\n } else {\n Log.e(TAG, \"SAVE: Canceled by user\");\n }\n }\n\n // ...\n\n }\n\nAfter storing credentials, retrieve them by calling\n[`CredentialsClient.request()`](/android/reference/com/google/android/gms/auth/api/credentials/CredentialsClient#request(com.google.android.gms.auth.api.credentials.CredentialRequest)).\n\nTargeting Android O and above\n-----------------------------\n\nWhen you save password credentials using Smart Lock on devices running Android O\nor newer, Smart Lock uses the native autofill confirmation dialog over its own\ndialog whenever possible. (Note that credentials saved using Autofill with\nGoogle are bi-directionally shared with Smart Lock for Passwords.)"]]