Online registration: Drupal+CiviMember
Most of what you're describing is handled automatically.  Here are some key elements that may help:


You must create the membership form as a contribution page.  Go to Contributions menu > Manage Contribution Pages and create a new page.  Be sure to fill out the "Membership" section.
A good reference can be found here.
To allow the user to become a Drupal user as part of signup, create a profile from Administer menu > Customize Data and Screens > Profiles.  In the profile settings, under "Advanced Settings", there is an option to allow someone to create a Drupal account while filling out the profile.  Once you've created the profile, add it to the contribution page from the "Include Profiles" tab.
You can decide whether or not to take either online (e.g. credit card) or offline (e.g. mailing in a check, aka "pay later") payments or both for your registration form.  If someone pays online, and the transaction is successful, they'll automatically receive a membership.  If you allow a "pay later" option, a membership will be created with a status of "pending".  It will not be counted as a membership for most purposes.  When you mark the contribution as complete, the membership will activate.