예제 #1
0
        /// <summary>
        /// Gets a new license for the given user and application
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="appID">Applicaton ID</param>
        /// <returns>License for the given user and application</returns>
        public static License GetNewLicense(User user, Guid appID)
        {
            if (user == null)
            {
                throw new Exception("A user must be specified");
            }
            else if (string.IsNullOrEmpty(user.Name))
            {
                throw new Exception("User name must be specified");
            }

            // Get the application
            Application application = ApplicationDAL.GetApplication(appID);

            if (application == null)
            {
                throw new Exception(string.Format("'{0}' is not a valid Appliation ID", appID.ToString()));
            }

            License license = new License()
            {
                Application = application,
                IssuedOn    = DateTime.Now,
                IssuedTo    = user,
                Key         = RegistrationDAL.GetUniqueLicenseKey()
            };

            InsertLicense(license);

            return(license);
        }
예제 #2
0
 /// <summary>
 /// Creates a License from the data contained in the data reader
 /// </summary>
 /// <param name="dr">Data reader</param>
 /// <returns>License containing data in data reader</returns>
 private static License FillLicense(DbDataReader dr)
 {
     return(new License()
     {
         Application = ApplicationDAL.FillApplication(dr),
         IssuedOn = (DateTime)dr.GetDateTime("IssuedOn"),
         IssuedTo = UserDAL.FillUser(dr),
         Key = dr.GetString("LicenseKey")
     });
 }
예제 #3
0
        /// <summary>
        /// Gets an authorization key for a given hardware ID, application ID, and license key
        /// </summary>
        /// <param name="hardwareID">Hardware ID</param>
        /// <param name="appID">Application ID</param>
        /// <param name="licenseKey">License key</param>
        /// <returns>Authorization key if parameters are valid, string.Empty otherwise</returns>
        public static string GetAuthorizationKey(string hardwareID, Guid appID, string licenseKey)
        {
            string authKey = string.Empty;

            if (string.IsNullOrEmpty(hardwareID))
            {
                throw new Exception("Hardware ID is missing");
            }
            else if (string.IsNullOrEmpty(licenseKey))
            {
                throw new Exception("License key is missing");
            }

            Application app = ApplicationDAL.GetApplication(appID);

            if (app == null)
            {
                throw new Exception(string.Format("'{0}' is not a valid Appliation ID", appID.ToString()));
            }

            License license = LicenseDAL.GetLicense(licenseKey, appID);

            if (license == null)
            {
                throw new Exception("The license key is not valid for this application");
            }

            if (license != null)
            {
                // Create Authorization key
                string seed = string.Concat(hardwareID, appID.ToString(), licenseKey);
                authKey = Utilities.Registration.GenerateSHA1Hash(seed);
            }

            InsertAuthorization(authKey, licenseKey, hardwareID);

            return(authKey);
        }