您正位於 MDN Web Docs 的可編輯版本

以 MDN Web Docs 使用者身分檢視: https://developer.mozilla.org/zh-TW/docs/Web/API/Credential

我們的志工尚未將本文翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!
您也可以閱讀本文的 English (US) 版本。

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The Credential interface of the Credential Management API provides information about an entity (usually a user) as a prerequisite to a trust decision.

Credential objects may be of 3 different types:

Properties

Credential.id Read only
Returns a DOMString containing the credential's identifier. This might be any one of a GUID, username, or email address.
Credential.type Read only
Returns a DOMString containing the credential's type. Valid values are password, federated and public-key. (For PasswordCredential, FederatedCredential and PublicKeyCredential)

Event handlers

None.

Methods

None.

Examples

let pwdCredential = new PasswordCredential({
  id: "example-username", // Username/ID
  name: "John Doe", // Display name
  password: "correct horse battery staple" // Password
});

console.assert(pwdCredential.type === "password");

Specifications

Specification Status Comment
Credential Management Level 1 Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Credential
Experimental
Chrome Full support 51Edge Full support 18Firefox Full support 60IE No support NoOpera Full support 38Safari Full support 13WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support YesOpera Android Full support 41Safari iOS Full support 13.3Samsung Internet Android Full support 5.0
id
Experimental
Chrome Full support 51Edge Full support 18Firefox Full support 60IE No support NoOpera Full support 38Safari Full support 13WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support YesOpera Android Full support 41Safari iOS Full support 13.3Samsung Internet Android Full support 5.0
name (from CredentialUserData mixin)
Experimental
Chrome No support 51 — 52
Notes
No support 51 — 52
Notes
Notes See Bug 602980.
Edge ? Firefox No support NoIE No support NoOpera No support 38 — 39
Notes
No support 38 — 39
Notes
Notes See Bug 602980.
Safari ? WebView Android No support 51 — 52
Notes
No support 51 — 52
Notes
Notes See Bug 602980.
Chrome Android No support 51 — 52
Notes
No support 51 — 52
Notes
Notes See Bug 602980.
Firefox Android No support NoOpera Android No support NoSafari iOS ? Samsung Internet Android No support 5.0 — 6.0
Notes
No support 5.0 — 6.0
Notes
Notes See Bug 602980.
type
Experimental
Chrome Full support 51Edge Full support 18Firefox Full support 60IE No support NoOpera Full support 38Safari Full support 13WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support YesOpera Android Full support 41Safari iOS Full support 13.3Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.