Fixing issues reported in google code
This commit is contained in:
parent
15a298afad
commit
5d1e6a1301
@ -5,20 +5,22 @@ using System.Text;
|
|||||||
|
|
||||||
namespace OTPNet
|
namespace OTPNet
|
||||||
{
|
{
|
||||||
|
// Issue reported by larry.ellis
|
||||||
|
// Patch provided by andrea.bertin
|
||||||
|
// https://code.google.com/p/otpnet/issues/detail?id=1
|
||||||
class Unixtime
|
class Unixtime
|
||||||
{
|
{
|
||||||
private DateTime date;
|
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
private readonly DateTime date;
|
||||||
|
|
||||||
public Unixtime()
|
public Unixtime()
|
||||||
{
|
{
|
||||||
this.date = DateTime.Now;
|
this.date = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Unixtime(int timestamp)
|
public Unixtime(int timestamp)
|
||||||
{
|
{
|
||||||
DateTime converted = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
this.date = Epoch.AddSeconds(timestamp);
|
||||||
DateTime newDateTime = converted.AddSeconds(timestamp);
|
|
||||||
this.date = newDateTime.ToLocalTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime toDateTime()
|
public DateTime toDateTime()
|
||||||
@ -28,8 +30,7 @@ namespace OTPNet
|
|||||||
|
|
||||||
public long toTimeStamp()
|
public long toTimeStamp()
|
||||||
{
|
{
|
||||||
TimeSpan span = (this.date - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToLocalTime());
|
return (long)this.date.Subtract(Epoch).TotalSeconds;
|
||||||
return Convert.ToInt64(span.TotalSeconds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,9 @@ namespace OTPNet
|
|||||||
|
|
||||||
public OTP(string secret, int digits)
|
public OTP(string secret, int digits)
|
||||||
{
|
{
|
||||||
|
// Issue reported by scox.nz
|
||||||
|
// https://code.google.com/p/otpnet/issues/detail?id=2
|
||||||
|
this.secret = secret;
|
||||||
this.digits = digits;
|
this.digits = digits;
|
||||||
this.digest = HashAlgorithm.SHA1;
|
this.digest = HashAlgorithm.SHA1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user