23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

for domain-joined machines—see table below). The purpose here is to show the dialog when a<br />

stored credential might be incorrect and the user is expected to provide a new one.<br />

• errorCode The numerical value of a Win32 error code (default is ERROR_SUCCESS) that will be<br />

formatted and displayed in the dialog box. You would use this when you obtain credentials from<br />

the picker initially but find that those credentials don’t work and need to invoke the dialog<br />

again. Instead of providing your own message, you just choose an error code and let the system<br />

do the rest. The most common values for this are 1326 (login failure), 1330 (password expired),<br />

2202 (bad username), 1907 or 1938 (password must change/password change required), 1351<br />

(can’t access domain info), and 1355 (no such domain). There are, in fact, over 15,000 Win32<br />

error codes, but that means you’ll have to search the reference linked here (or search within the<br />

winerror.h file typically found in your Program Files (x86)\Windows Kits\8.0\Include\shared<br />

folder). Happy hunting!<br />

• callerSavesCredential A Boolean indicating that the app will save the credential and that the<br />

picker should not. The default value is false. When set to true, credentials are saved to a secure<br />

system location (not the credential locker) if the app has the Enterprise Authentication capability<br />

(see below).<br />

• credentialSaveOption A value from the CredentialSaveOption enumeration indica-ting the<br />

initial state of the Remember My Credentials check box: unselected, selected, or hidden.<br />

• authenticationProtocol A value from the AuthenticationProtocol enumeration: basic,<br />

digest, ntlm, kerberos, negotiate (the default), credSsp, and custom (in which case you must<br />

supply a string in the customAuthenticationProcotol property). Note that with basic and<br />

digest, the CredentialPickerResults.credentialPassword will not be encrypted and is subject<br />

to the same security needs as a plain text password you collect from your own UI.<br />

Here’s an example of invoking the picker with an errorCode indicating a previous failed login:<br />

var options = new Windows.Security.Credentials.UI.CredentialPickerOptions();<br />

options.message = "Please enter your credentials";<br />

options.caption = "Sample App";<br />

options.targetName = "Target";<br />

options.alwaysDisplayDialog = true;<br />

options.errorCode = 1326; // Shows "The username or password is incorrect."<br />

options.callerSavesCredential = true;<br />

options.authenticationProtocol =<br />

Windows.Security.Credentials.UI.AuthenticationProtocol.negotiate;<br />

options.credentialSaveOption = Windows.Security.Credentials.UI.CredentialSaveOption.selected;<br />

Windows.Security.Credentials.UI.CredentialPicker.pickAsync(options)<br />

.done(function (results) {<br />

}<br />

658

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!