Is there a standard to store username and password in WP7 applications?

前端 未结 2 1340
执笔经年
执笔经年 2021-02-01 20:48

I would like to ask if there is a standard to store username and password in a Windows Phone application. I am working on a project that validates the user on every request tha

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 21:27

    Use ProtectedData. I found this example on Kevin D. Wolf's efficientcoder.net :

       public static String Password {
            get {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(STR_PASSWORÐ)) {
                    var bytes = IsolatedstorageSettings.Applicationsettings[STR_PASSwORÐ] as byte[];
                    var unEncrypteBytes = ProtectedData.Unprotect(bytes, null);
                    return Encoding.UTF8.GetString(unEncrypteBytes, 0, unEncrypteBytes.Length);
                } else {
                    return string.Empty; 
                }
            }
            set {
                var encryptedBytes = ProtectedData.Protect(Encoding.UTF8.GetBytes(value), null);
                IsolatedStorageSettings.ApplicationSettings[STR_PASSWORÐ] = encryptedBytes;
            }
       }
    

    (Apologies for the cut and paste I had to use a text from image scan)

提交回复
热议问题