با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پس از اینکه کاربران با موفقیت به سیستم وارد شدند، حساب ایجاد کردند یا رمز عبور را تغییر دادند، به آنها اجازه دهید اعتبارنامههای خود را ذخیره کنند تا احراز هویت آینده در برنامه شما خودکار شود.
یک شی Credential حاوی اطلاعات ورود به سیستم کاربر ایجاد کنید. به عنوان مثال، برای اینکه به کاربران اجازه دهید پس از ورود موفقیت آمیز با رمزهای عبور خود، اطلاعات کاربری خود را ذخیره کنند:
سپس، CredentialsClient.save() را فراخوانی کنید تا اعتبار کاربران ذخیره شود. اگر تماس با CredentialsClient.save() فوراً موفقیت آمیز نباشد، اعتبارنامه ممکن است جدید باشد، در این صورت کاربر باید درخواست ذخیره را تأیید کند. ResolvableApiException را با startResolutionForResult() حل کنید تا از کاربر درخواست تایید شود.
اگر کاربر تصمیم بگیرد اعتبارنامه ها را ذخیره نکند، دیگر از کاربر خواسته نمی شود که اعتبار هیچ حساب کاربری را برای برنامه ذخیره کند. اگر پس از انصراف کاربر با CredentialsClient.save() تماس بگیرید، نتیجه آن دارای کد وضعیت CANCELED خواهد بود. کاربر می تواند بعداً از برنامه تنظیمات Google در بخش Smart Lock for Passwords شرکت کند. کاربر باید ذخیره اعتبارنامه را برای همه حساب ها فعال کند تا دفعه بعد از شما خواسته شود که اعتبارنامه ها را ذخیره کنند.
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 for Passwords به اشتراک گذاشته می شود.)
تاریخ آخرین بهروزرسانی 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.)"]]