New Authorization System

Discussion in 'Code Snippets and Tutorials' started by Lightning, Feb 4, 2012.

  1. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Introduction
    Due to recent attempts to crack programs and just the need for a new authorization, I have created a .dll file that can referenced and used for authorization within the .NET framework. This guide will show you all the functions for the new authorization, for both novice and advanced programmers.



    Table of Contents
    I. The Functions of the Authorization
    II. Using in Visual Studio
    III. Example Usage (VB.NET)
    IV. Example Usage (C#)
    V. Download (For Programmers)


    For the old authorization, please check here: post182797.html#p182797
     
  2. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    The Functions of the Authorization

    The Functions of the Authorization


    Delegates
    (Delegate) dUpdateAvailable()
    (Delegate) dUnAuthorized()
    (Delegate) dExceptionHandle(Exception ex)
    (Delegate) dAuthorized()
    (Delegate) dAuthorizedWithStats(Dictionary<string, string> stats)
    [fitbox=145]Dictionary<string, int> stats keys:
    (String) Username: User's username.
    (String) Posts: User's post count.
    (String) Reputation: User's reputation points.
    (String) Cash: User's Forum Cash.
    (String) Last Visit: User's last visit.
    (String) Rank: User's rank.
    (String) Group: User's default group.[/fitbox]
    (Delegate) dInactive(Dictionary<string, int> info)
    [fitbox=100]Dictionary<string, int> info keys:
    • Posts Required: The minimum amount of posts by the user to use the program.
    • Days: The span of days to check for user activity. If set to 0, authorization will check total post count.
    • Posts: The amount of posts the user currently has.
    • Posts Left: The amount of posts left that the user must make to be authorized.
    [/fitbox]





    Constructor
    [Optional] (String) strUsername: The username to set the Neofriends.net authorization to.
    [Optional] (String) strPassword: The password corresponding to the username to authorize.
    [Optional] (String) strProgramID: The identification number (ID) of the program to authorize.
    [Optional] (String) strProgramName: The name of the program to authorize. Must be exact match to name in downloads section.
    [Optional] (Control) InvokeControl: The control to invoke when calling a Sub.
    [Optional] (Integer) iTimeout: The maximum time (in milliseconds) to wait for an authorization response.
    [Optional] (Integer) iActivityPosts: The minimum posts by the user to use the program.
    [Optional] (Integer) iActivityDays: The span of days to check for user activity. If set to 0, authorization will check total post count.
    [Optional] (Boolean) bShowMsgBox: The option whether to show message boxes.
    [Optional] (Boolean) bGetStats: The option whether to get statistics after a successful authorization.
    [Optional] (dUpdateAvailable) UpdateSub: The function to invoke if authorization finds an update available.
    [Optional] (dAuthorized) AuthorizedSub: The function to invoke if the authorization finds the user authorized without retrieving statistics.
    [Optional] (dAuthorizedWithStats) AuthorizedWithStatsSub: The function to invoke if the authorization finds the user authorized after retrieving statistics.
    [Optional] (dUnAuthorized) UnAuthorizedSub: The function to invoke if authorized finds the user unauthorized.
    [Optional] (dExceptionHandle) ExceptionSub: The function to invoke if an exception is thrown during authorization.
    [Optional] (dInactive) InactiveSub: The function to invoke if the authorization finds the user inactive.
    [Optional] (Label) lblStatus: The label to update with the latest authorization status.
    [Optional] (ToolStripLabel) tsStatus: The ToolStripLabel to update with the latest authorization status.
    [Optional] (NotifyIcon) ni: The NotifyIcon to show balloons with the latest authorization status.





    Properties
    (String) Username: The username to set the Neofriends.net authorization to.
    (String) Password: The password corresponding to the username to authorize.
    (String) ProgramID: The identification number (ID) of the program to authorize.
    (String) ProgramName: The name of the program to authorize. Must be exact match to name in downloads section.
    (Control) InvokeControl: The control to invoke when calling a Sub.
    (Integer) Timeout: The maximum time (in milliseconds) to wait for an authorization response.
    (Integer) ActivityPosts: The minimum posts by the user to use the program.
    (Integer) ActivityDays: The span of days to check for user activity. If set to 0, authorization will check total post count.
    (Label) StatusLabel: The label to update with the latest authorization status.
    (ToolStripLabel) TSStatusLabel: The ToolStripLabel to update with the latest authorization status.
    (NotifyIcon) TrayIcon: The NotifyIcon to show balloons with the latest authorization status.
    (dUpdateAvailable) UpdateSub: The function to invoke if authorization finds an update available.
    (dAuthorized) AuthorizedSubNoStats: The function to invoke if the authorization finds the user authorized without retrieving statistics.
    (dAuthorizedWithStats) AuthorizedSub: The function to invoke if the authorization finds the user authorized after retrieving statistics.
    (dUnAuthorized) UnAuthorizedSub: The function to invoke if authorized finds the user unauthorized.
    (dExceptionHandle) ExceptionSub: The function to invoke if an exception is thrown during authorization.
    (dInactive) InactiveSub: The function to invoke if the authorization finds the user inactive.
    [Read-Only] (Boolean) IsAuthorized: Returns whether the user is authorized to use this program.
    (Boolean) ShowMsgBox: Gets or sets whether to show interactive messageboxes with user.
    [Read-Only] (Integer) Progress: Gets the percentage complete out of 100.
    (Boolean) GetStatistics: Gets or sets whether to get statistics after a successful authorization.





    Methods
    (Void) Import: Imports the specified parameters to the instance of NFAuth. If parameters are left empty or with their default values, their values are left unchanged.
    [fitbox=125][Optional] (String) strUsername: The username to set the Neofriends.net authorization to.
    [Optional] (String) strPassword: The password corresponding to the username to authorize.
    [Optional] (String) strProgramID: The identification number (ID) of the program to authorize.
    [Optional] (String) strProgramName: The name of the program to authorize. Must be exact match to name in downloads section.
    [Optional] (Control) InvokeControl: The control to invoke when calling a Sub.
    [Optional] (Integer) iTimeout: The maximum time (in milliseconds) to wait for an authorization response.
    [Optional] (Integer) iActivityPosts: The minimum posts by the user to use the program.
    [Optional] (Integer) iActivityDays: The span of days to check for user activity. If set to 0, authorization will check total post count.
    [Optional] (dUpdateAvailable) UpdateSub: The function to invoke if authorization finds an update available.
    [Optional] (dAuthorized) AuthorizedSub: The function to invoke if the authorization finds the user authorized without retrieving statistics.
    [Optional] (dAuthorizedWithStats) AuthorizedWithStatsSub: The function to invoke if the authorization finds the user authorized after retrieving statistics.
    [Optional] (dUnAuthorized) UnAuthorizedSub: The function to invoke if authorized finds the user unauthorized.
    [Optional] (dExceptionHandle) ExceptionSub: The function to invoke if an exception is thrown during authorization.
    [Optional] (dInactive) InactiveSub: The function to invoke if the authorization finds the user inactive.
    [Optional] (Label) lblStatus: The label to update with the latest authorization status.
    [Optional] (ToolStripLabel) tsStatus: The ToolStripLabel to update with the latest authorization status.
    [Optional] (NotifyIcon) ni: The NotifyIcon to show balloons with the latest authorization status.[/fitbox]


    (Boolean) Authorize: Authorize with Neofriends synchronously using the information provided. Returns whether authorization was successful.

    (Void) AuthorizeASync: Authorize with Neofriends asynchronously using the information provided.
     
  3. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Using in Visual Studio

    [​IMG]

    Go to Project -> Add Reference...





    [​IMG]

    Click on the 'Browse' tab and find NFAuth.dll.




    [​IMG]

    Once loaded, this should show up under the Project's References like this. Click on NFAuth.




    [​IMG]

    The 'Properties' window should appear as follows. Make sure that Copy Local is set to true.






    You should be all set to go!

    Remember to import the 'Authorization' namespace.

    For VB.NET programmers, put this before the class (in the imports):
    Code (Text):
    1. Imports Authorization
    For C# programmers, put this before the class (in the imports):
    Code (Text):
    1. using Authorization;
     
  4. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Example Usage (VB.NET)

    Example Usage (VB.NET)



    For syntax highlight, go here: http://pastebin.com/A9Dr1igK


    Code (Text):
    1. Imports System.Collections
    2. Imports System.Collections.Generic
    3. Imports System.Text
    4. Imports System.Windows.Forms
    5. Imports Authorization
    6.  
    7. Public Partial Class frmMain
    8.     Inherits Form
    9.     Public Sub New()
    10.         InitializeComponent()
    11.     End Sub
    12.  
    13.     #Region "Authorization"
    14.  
    15.     Private Sub btnAuthorize_Click(sender As Object, e As EventArgs)
    16.         'Validate that user has entered correct information in textboxes.
    17.  
    18.         'Use NFAuth's constructor to your full advantage
    19.         Dim auth As New NFAuth(txtUsername.Text, txtPassword.Text, PROGRAM_ID, PROGRAM_NAME, Me, UpdateSub := AddressOf Auth_UpdateHandler, _
    20.             AuthorizedSub := AddressOf Auth_AuthorizedHandler, UnAuthorizedSub := AddressOf Auth_UnauthorizedHandler, ExceptionSub := AddressOf Auth_ExceptionHandler)
    21.  
    22.         'Settings can also be set like this:
    23.         auth.StatusLabel = lblStatus
    24.  
    25.         'Authorize asynchronously so it doesn't freeze the GUI
    26.         auth.AuthorizeASync()
    27.  
    28.         'Disable your authorize button
    29.         btnAuthorize.Enabled = False
    30.     End Sub
    31.  
    32.     Private Sub Auth_ExceptionHandler(ex As Exception)
    33.         'Handle the exception (stuff like Debug.Print() might help with debugging)
    34.     End Sub
    35.  
    36.     Private Sub Auth_AuthorizedHandler()
    37.         'Do something when they are authorized
    38.     End Sub
    39.  
    40.     Private Sub Auth_UnauthorizedHandler()
    41.         btnAuthorize.Enabled = True
    42.         'Do something for handling unauthorized.
    43.     End Sub
    44.  
    45.     Private Sub Auth_UpdateHandler()
    46.         'You can either require the user to update before using or just use the outdated version.
    47.     End Sub
    48.  
    49.     #End Region
    50. End Class
     
  5. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Example Usage (C#)

    Example Usage (C#)


    For syntax highlight, go here: http://pastebin.com/E2R6xBru

    Code (Text):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Text;
    6. using System.Windows.Forms;
    7. using Authorization;
    8.  
    9. public partial class frmMain : Form
    10. {
    11.     public frmMain()
    12.     {
    13.         InitializeComponent();
    14.     }
    15.  
    16.     #region "Authorization"
    17.    
    18.     private void btnAuthorize_Click(object sender, EventArgs e)
    19.     {
    20.         //Validate that user has entered correct information in textboxes.
    21.        
    22.         //Use NFAuth's constructor to your full advantage
    23.         NFAuth auth = new NFAuth(txtUsername.Text, txtPassword.Text, PROGRAM_ID, PROGRAM_NAME, this, UpdateSub: Auth_UpdateHandler, AuthorizedSub: Auth_AuthorizedHandler, UnAuthorizedSub: Auth_UnauthorizedHandler, ExceptionSub: Auth_ExceptionHandler);
    24.  
    25.         //Settings can also be set like this:
    26.         auth.StatusLabel = lblStatus;
    27.  
    28.         //Authorize asynchronously so it doesn't freeze the GUI
    29.         auth.AuthorizeASync();
    30.  
    31.         //Disable your authorize button
    32.         btnAuthorize.Enabled = false;
    33.     }
    34.  
    35.     private void Auth_ExceptionHandler(Exception ex)
    36.     {
    37.         //Handle the exception (stuff like Debug.Print() might help with debugging)
    38.     }
    39.  
    40.     private void Auth_AuthorizedHandler()
    41.     {
    42.         //Do something when they are authorized
    43.     }
    44.  
    45.     private void Auth_UnauthorizedHandler()
    46.     {
    47.         btnAuthorize.Enabled = true;
    48.         //Do something for handling unauthorized.
    49.     }
    50.  
    51.     private void Auth_UpdateHandler()
    52.     {
    53.         //You can either require the user to update before using or just use the outdated version.
    54.     }
    55.  
    56.     #endregion
    57. }
     
  6. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Download

    Download

    Before downloading, I would like to thank tharoux and ricky92. Tharoux for him trusting me and helping me with this authorization. Ricky92 for his existing code that this new authorization is based off of.


    Zip Hashes
    • SHA1: 4F8E4331E82062382B0486F9AF973DAEC382A935
    • MD5: CFE2183841126634EEC14392183B54FA


    NFAuth.dll Hashes
    • SHA1: A461956F6969798FAE744F04AED365C92805437F
    • MD5: 836189EE243158982B691749B1972FBB


    Download:
     
    Shawn likes this.
  7. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Version 2.0

    New Features
    • Major security updates
    • Updated for faster authorization
    • Added optional activity monitor for the programmer
    • Many minor internal changes
     
  8. expon

    expon Administrator
    Staff Member

    Joined:
    Oct 30, 2006
    Messages:
    1,393
    Likes Received:
    56
    Location:
    UK
    Apparently the auth username is case sensitive.. perhaps change that in future versions :p
     
  9. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    It's not due to the authorization system itself, it was the database's collation which caused usernames to be case sensitive. I've changed it, and it should be working as expected now ;)
     
  10. expon

    expon Administrator
    Staff Member

    Joined:
    Oct 30, 2006
    Messages:
    1,393
    Likes Received:
    56
    Location:
    UK
    ah ok, great thanks Ricky :)
     
  11. nog_lorp

    nog_lorp Newbie

    Joined:
    Jan 18, 2013
    Messages:
    32
    Likes Received:
    1
    You oughta add crc checking!
     
  12. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    Version 2.1

    New Features
    • New statistics retrieval method
    • Cleaner codebase