Showing posts with label PROCESS. Show all posts
Showing posts with label PROCESS. Show all posts

Friday, December 19, 2014

PROGRAMMING: C# CODE TO GENERATE RANDOM PASSWORDS DEVELOPER TUTORIAL

C# CODE TO GENERATE RANDOM PASSWORDS - DEVELOPED BY JAY STILLA + CO. MISTERBOTS



Here is a very useful C# code snippet for generating random strong passwords. The password is generated using upper case and lower case alphabets, numerals and special characters.


//create constant strings for each type of characters
static string alphaCaps = "QWERTYUIOPASDFGHJKLZXCVBNM";
static string alphaLow = "qwertyuiopasdfghjklzxcvbnm";
static string numerics = "1234567890";
static string special = "@#$";
//create another string which is a concatenation of all above
string allChars = alphaCaps + alphaLow + numerics + special;
Random r = new Random();
public string GenerateStrongPassword(int length)
{
    String generatedPassword = "";
    if (length < 4)
        throw new Exception("Number of characters should be greater than 4.");
    // Generate four repeating random numbers are postions of
    // lower, upper, numeric and special characters
    // By filling these positions with corresponding characters,
    // we can ensure the password has atleast one
    // character of those types
    int pLower, pUpper, pNumber, pSpecial;
    string posArray = "0123456789";
    if (length < posArray.Length)
        posArray = posArray.Substring(0, length);
    pLower = getRandomPosition(ref posArray);
    pUpper = getRandomPosition(ref posArray);
    pNumber = getRandomPosition(ref posArray);
    pSpecial = getRandomPosition(ref posArray);
    for (int i = 0; i < length; i++)
    {
        if (i == pLower)
            generatedPassword += getRandomChar(alphaCaps);
        else if (i == pUpper)
            generatedPassword += getRandomChar(alphaLow);
        else if (i == pNumber)
            generatedPassword += getRandomChar(numerics);
        else if (i == pSpecial)
            generatedPassword += getRandomChar(special);
        else
            generatedPassword += getRandomChar(allChars);
    }
    return generatedPassword;
}
private string getRandomChar(string fullString)
{
    return fullString.ToCharArray()[(int)Math.Floor(r.NextDouble() * fullString.Length)].ToString();
}
private int getRandomPosition(ref string posArray)
{
    int pos;
    string randomChar = posArray.ToCharArray()[(int)Math.Floor(r.NextDouble()
                                   * posArray.Length)].ToString();
    pos = int.Parse(randomChar);
    posArray = posArray.Replace(randomChar, "");
    return pos;
}

SCANNING RUNNING PROCESSES IN C# [C-SHARP] OPEN SOURCE CODE



SCANNING RUNNING PROCESSES IN C# [C-SHARP] OPEN SOURCE CODE - BUILD A BOT & TOP BOTS CODERS MISTER AND JASON JAY STILLA LEE

Labels: 
Using System.Diagnostics we can know the processes currently running in our machine.The code is quite simple. In the following demo, we will show all the processes running on your machine, plus a check if you are running Windows Live Messenger (a.k.a. MSN Messenger).


using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace CheckRunningProcesses
{
class Program
{
static void Main(string[] args)
{
const string messenger = "msnmsgr";
bool runningMessenger = false;

// Get Collection of running processes from Process Static method
Process[] processes = Process.GetProcesses();

// Scan processes in the obtained collection
foreach (Process p in processes)
{
Console.WriteLine(p.ProcessName);

if (p.ProcessName == messenger)
{
runningMessenger = true;
}
}

if (runningMessenger)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("You have Windows Live Messenger (MSN) Running"); 
}

Console.ReadLine();
}
}
}


Note: The above code does not check whether you are signed in to the msn service. It just checks whether the MSN executable is running.