/// <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 FaultException <Faults.InvalidUserFault>(new Faults.InvalidUserFault("A user must be specified"), "User not set to instance of an object"); } else if (string.IsNullOrEmpty(user.Name)) { throw new FaultException <Faults.InvalidUserFault>(new Faults.InvalidUserFault("User name must be specified"), "Name property missing"); } // Get the application Application application = ApplicationDAL.GetApplication(appID); if (application == null) { throw new FaultException <Faults.InvalidApplicationFault>(new Faults.InvalidApplicationFault("The application ID is not valid"), "Invalid application ID"); } License license = new License() { Application = application, IssuedOn = DateTime.Now, IssuedTo = user, Key = RegistrationDAL.GetUniqueLicenseKey() }; InsertLicense(license); return(license); }
/// <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 FaultException <InvalidParameterFault>(new InvalidParameterFault("Hardware ID is missing"), "Missing parameter"); } else if (string.IsNullOrEmpty(licenseKey)) { throw new FaultException <InvalidParameterFault>(new InvalidParameterFault("License key is missing"), "Missing parameter"); } Application app = ApplicationDAL.GetApplication(appID); if (app == null) { throw new FaultException <InvalidApplicationFault>(new InvalidApplicationFault("The application ID is not valid"), "Invalid application ID"); } License license = LicenseDAL.GetLicense(licenseKey, appID); if (license == null) { throw new FaultException <InvalidParameterFault>(new InvalidParameterFault("The license key is not valid for this application"), "Invalid license key"); } 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); }