Forum Xamarin.Android

Saving a password on android

Hi, I'm currently trying to save a password on android.

Im fairly new to coding for apps, I have implemented this on the iOS side (with help)

public bool SavePassword(string Username, string Password) {
        try {
            var s = new SecRecord (SecKind.GenericPassword) {
                Label = "Creds",
                Account = Username.Trim().ToLower(),
                Service = "Creds",
                ValueData = NSData.FromString (Password),
            var err = SecKeyChain.Add (s);
            if (err == SecStatusCode.DuplicateItem) {
                SecKeyChain.Remove (s);
                var err2 = SecKeyChain.Add (s);

            if (err != SecStatusCode.DuplicateItem) return true;
            else return false;

            //if (err != SecStatusCode.Success && err != SecStatusCode.DuplicateItem)
            //DisplayMessage ("Error adding record: {0}", err);
        catch (Exception ex) {
            return false;

this works fine, however, as i have not coded for android before, i am having a little trouble passing this method over.

I have found a couple of tutorials online using KeyStore but none of these seem to work or return what i need.

any help or links to a more detailed (reasons behind code) explanation would be a great help.

thanks in advance.

Best Answer


Sign In or Register to comment.