Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
HI friends,
i have a task that is automatically generate a password in this case i use date,time and no of days.But one condition is there the password is valid for that days and greater than that days the application is run not automatically.


String pwd, noofdays;
noofdays = textBox2.Text;
pwd = DateTime.Now.ToString("yyyyMMdd1221" + "+" + noofdays);
textBox3.Text = pwd;
Posted
Updated 13-Jun-11 21:26pm
v3
Comments
Sergey Alexandrovich Kryukov 14-Jun-11 2:59am    
Not clear how validation is related to date.
--SA

Without seeing and code, it is difficult to help you, but I suspect that you need to check the password validity when you log them in. However, you do realize that there is a simple way round this, for a windows app, don't you? Change the date, log in, change the date back... You should also be aware that 1) users like to change passwords, because otherwise they don't remember them and have to write them down, and 2) passwords should be stored in a hashed form to prevent reverse engineering: this means that you cannot recover the original password to check the validity of the date unless you keep a copy when he logs in!

You might want to think a bit more carefully about what you are trying to do before you spend too much time creating a date-based password...
 
Share this answer
 
I think you need to store both of user name and password after creating the password. but :
If the security is not very important (!) you can generate password without storing it in database.

for example:

C#
public string GeneratePassword(string userName)
{
    if (string.IsNullOrEmpty(userName))
        return "NAN";

    userName = userName.ToUpper();

    return string.Format("{0}{1}{2}{3}", "8080110001",EncryptedUserName(userName), userName, DateTime.Now);
}

public int EncryptedUserName(string userName)
{
    int partOfSecurity = 0;
    foreach (char c in userName)
    {
        partOfSecurity += (int)c;
    }
    return partOfSecurity;
}
public bool IsAuthenticated(string userName, string passWord)
{
    if (string.IsNullOrEmpty(userName) || passWord.Length <10)
        return false;
     userName = userName.ToUpper();



     return
         (passWord.Substring(0, 10) == "8080110001" && passWord.Replace(EncryptedUserName(userName).ToString(), string.Empty) != passWord && passWord.Replace(userName, string.Empty) != passWord)
         ? true : false;
}



But, I emphasize that it's a poor security.
 
Share this answer
 
v3
First of all for using this feature you have to create a date check function it may contains getdate(). if and only if this condition will true then you have to create passwordCheck function for validation password because that password is going to expire in only 1 day. And for generating automatic password creation you can use Cryptography classes of .NET... Hope It Will Help You
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900