Xamarin Visual Studio Android C# How to validate couchbase lite credentials
<p>I am working on an application, which requires the user to enter the DB I.P. and port the first time the application is run. I have created a class called Database.cs (code to follow), which handles the authentication. Everything works fine if the proper information is entered; however, I have no way of validating if the incorrect information is added. I know I can by hard coding it, but I am looking for a way to handle it without resorting to hard coding. </p>

<p>Database.cs</p>

<pre><code>    using System;
    using Android.Util;

    using Couchbase.Lite;
    using Couchbase.Lite.Auth;

    namespace Core
    {
    public class Database
    {
        static readonly string TAG = "eTest: " + typeof(Database).Name;
        const string DB_NAME = "dev";

        public static Couchbase.Lite.Database db;

        static public Replication pull;
        static public Replication push;


        public static void CreateDatabase()
        {
            try
            {
                Log.Debug(TAG, "Entering method CreateDatabase try block");
                db = Manager.SharedInstance.GetDatabase(DB_NAME);
                Log.Debug(TAG, "Exiting method CreateDatabase try block");
            }
            catch (Exception e)
            {
                Log.Debug(TAG, "Entering method CreateDatabase catch block");
                Log.Error(TAG, "Error getting database", e);
                Log.Debug(TAG, "Exiting method CreateDatabase catch block");
                return;
            }
        }

        public static Uri CreateSyncUri(string host, int port)
        {
            Log.Debug(TAG, "Entering method CreateSyncUri");
            Uri syncUri = null;
            string scheme = "http";
            try
            {
                Log.Debug(TAG, "Entering try block of method CreateSyncUri");
                var uriBuilder = new UriBuilder(scheme, host, port, DB_NAME);
                syncUri = uriBuilder.Uri;
                Log.Debug(TAG, "Exiting try block of method CreateSyncUri");
            }
            catch (UriFormatException e)
            {
                Log.Error(TAG, " Cannot Create sync uri", e);
            }

            return syncUri;
        }

        public static void StartReplicationWithAuth(string host, int port)
        {
            Log.Debug(TAG, "Entering method StartReplicationWithAuth");
            pull = db.CreatePullReplication(CreateSyncUri(host, port));
            push = db.CreatePushReplication(CreateSyncUri(host, port));
            var authenticator = AuthenticatorFactory.CreateBasicAuthenticator("name", "password");
            pull.Authenticator = authenticator;
            push.Authenticator = authenticator;
            pull.Continuous = true;
            push.Continuous = true;
            pull.Start();
            push.Start();
            Log.Debug(TAG, "Exiting method StartReplicationWithAuth");
        }
    }
}
</code></pre>