Specify expiration for Parse Session token - security

Is there any way to change the expiration of a Parse session token to something other than 1 year or no-expiry?
Ideally I'd like to change the expiry to something like 14 days.

Related

How to use python to generate simple int or digit password valid within duration of time?

I'm setting up a new server, and want to assign a simple 6 digits(or int) password for my app to my user, so that each user have my authenticated password to do something.
I know that I could use secrets.token_hex(3) or something, but it will change over everytime I run my script. I want the password not to be changed within a certain amount of time once generated, and dedicated for just one user.
my database is based on sql structure, so it will automatically add new row of data in 'site.db' file. like:
{'id':1, 'username':'john', 'photo':'sdlfj.png'}, {'id':2, 'username':'Mary', 'photo':'dfasdfj.png'}
but I want to write a new file 'assignment.db' to fetchall the data in 'site.db', and struture it like
`{'id':1, 'username':'john', 'password': 984657}, {'id':2, 'username':'Mary', 'password':689795}`
in a condition not affecting 'site.db' file
using secrets, I can do it, but since every time I run the script, all the user's password is overwritten, any simple method to do that?

Persistent SimpleCookie

I'm trying to store a persistent cookie with SimpleCookie, so that I'm doing something like:
def add_cookie(self, name, value, expiry = None):
self.cookies[name] = value
if expiry is not None:
self.cookies[name]['expires'] = expiry
print(self.cookies[name].OutputString())
Output of print:
remember_me=blabla; expires=Sun, 02 Jul 2017 13:30:57 GMT
Of course then it's passed to wsgiref.simple_server's start_response function, with something like
(Set-Cookie, cookie['remember_me'].OutputString())
and the cookie is created on browser/client side, however expiry time is not updating.
Any idea how to set the correct expiry time and make persistent cookie instead of session cookie?
Thanks.
Issue solved, the described method is fine, I was just rewriting the expiry next time automatically, and that's why expiry disappeared always.

Destroy a session in Load Impact

I have created a user scenario in Load Impact to simulate a couple of hundred users in our web store.
The problem is that I can't seem to simulate the users in our Azure Queue.
The queue is only increasing with +1 users and not the hundreds of users as I want :)
I have created a random correlation id, but it seems like the session is still there.
Is there a way to destroy the session so when the script is looping a new session is created?
I found a LUA reference that says destroy:session but it wont work for me.
function rnd()
return math.random(0000, 9999)
end
{"POST", "http://STORE.////",
headers={["Content-Type"]="application/json;charset=UTF-8"},
data="{\"ChoosenPhoneModelId\":0,\"PricePlanId\":\"phone\",\"CorrelationId\":\"e97bdaf6-ed61-4fb3-".. rnd().."-d3bb09789feb\",\"ChoosenPhoneColor\":{\"Color\":1,\"Code\":\"#d0d0d4\",\"Name\":\"Silver\",\"DeliveryTime\":\"1-2 veckor\",\"$$hashKey\":\"005\"},\"ChoosenAmortization\":{\"AmortizationLength\":24,\"Price\":312,\"$$hashKey\":\"00H\"},\"ChoosenPriceplan\":{\"IsPostpaid\":true,\"IsStudent\":false,\"IsSenior\":false,\"Title\":\"Fast \",\"Description\":\"Hello.\",\"MonthlyAmount\":149,\"AvailiableDataPackages\":null,\"SubscriptionBinding\":1,\"$$hashKey\":\"00M\"},\"ChoosenDataPackage\":{\"Description\":\"20
GB\",\"PricePerMountInKr\":149,\"DataAmountInGb\":20,\"$$hashKey\":\"00U\"}}",
auto_decompress=true}
})
Any tips on how to.
Thanks in advance.
The correlation id isn't a random number. It's set by your server in a cookie. Get and use like this:
local response = http.request_batch({
{"GET", "http://store.///step1", auto_decompress=true},
})
-- extract correlation Id
local strCorrelationId = response[1].cookies['corrIdCookie']
{"POST", "http://STORE.////",
headers={["Content-Type"]="application/json;charset=UTF-8"},
data="{\"ChoosenPhoneModelId\":0,\"PricePlanId\":\"phone\",\"CorrelationId\":\"".. strCorrelationId .. "",\"ChoosenPhoneColor\":{\"Color\":1,\"Code\":\"#d0d0d4\",\"Name\":\"Silver\",\"DeliveryTime\":\"1-2 veckor\",\"$$hashKey\":\"005\"},\"ChoosenAmortization\":{\"AmortizationLength\":24,\"Price\":312,\"$$hashKey\":\"00H\"},\"ChoosenPriceplan\":{\"IsPostpaid\":true,\"IsStudent\":false,\"IsSenior\":false,\"Title\":\"Fast \",\"Description\":\"Hello.\",\"MonthlyAmount\":149,\"AvailiableDataPackages\":null,\"SubscriptionBinding\":1,\"$$hashKey\":\"00M\"},\"ChoosenDataPackage\":{\"Description\":\"20
GB\",\"PricePerMountInKr\":149,\"DataAmountInGb\":20,\"$$hashKey\":\"00U\"}}",
auto_decompress=true}
})
That is what makes your user unique. If you set CorrelationId to just any random number your server will simply not accept the session in your queue.
Once it's unique and correct your server will accept the POST properly.

Date timezone conversion socket.io

I'm writing a chat program using node.js and socket.io. When a user sends a message, I'd like the time at which they sent it to be emitted. Instead of the Date data being in the timezone of the person who sent it, however, I'd like it to be converted to the timezones of the respective recievers. Will JavaScript take care of this automatically, or is it something I need to fix?
socket.emit('chat', {
message: 'message',
date: new Date()
}
You can simply send the UTC value from the Date back to your server and up to another client. Even if they have different time zones, the local client will convert from the UTC value to that time zone when the Date is displayed.
It is important that the date is sent as UTC and not in the local time zone.
This can be an integer number (which will be milliseconds since 1/1/1970 UTC), obtained from .getTime(). All browsers support this, but it's not a very human readable format.
It can also be a string in ISO8601/RFC3339 format at UTC, such as 2013-06-26T15:40:00Z, which can be obtained by .toISOString().
What you can't do is just pass a Date object directly, as you showed in your sample. Socket.io will just call .toString() on it. That will end up sending a human readable RFC822 formatted string with the local time zone - not the UTC value that you want.
Javascript date object in different locale and timezone
This answer looks good. Store all your dates as UTC and then translate to receivers time zone.

Reminder Service in C#.Net 4.0 using UTC Time

I have a Windows Service that runs on my
Texas origin Server Central Time.
This will check for all active reminders and compares the reminder time that user wants and send out reminder if it matches with user required time.
Scenarios
User is from EST
User set up a reminder for *1:25 PM * using UI via my website
On submit, my C# business logic converts this time to UTC before storing in my database. That will become '18:25:00'
My Business logic will pull all Active reminders from DB
And checks for reminder time if current UTC time and Reminder setup time diffrence is less then 5 mins, then it will send notification to that customer.
this is how my logic written
DateTime CurrentDate = DateTime.Now.ToUniversalTime();
TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
if (Reminder.DailyReminders.Any(x => currentTime.Subtract(x.ReminderTime).TotalMinutes < 5
&& currentTime.Subtract(x.ReminderTime).TotalMinutes > 0))
{
if (Reminder.ReminderMedhodID.Equals(1))
_email.ComposeEmail(Reminder);
}
My Problem is
*currentTime* is always 1 hour behind to user requested reminder time SO my reminders are going out 1 hour late.
Note : currentTime is from below
TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
I am not sure if this is the best way to handle this requirement. considering this is one of the way, can any on help how to fix this issue?
Thanks to peter's answer
Can any one help me how to take user input time with Daylight consideration
This what i have so far
public TimeSpan ConvertToUTCTime(string dateStr)
{
DateTime localDateTime = DateTime.Parse(dateStr); // Local .NET timeZone.
DateTime utcDateTime = localDateTime.ToUniversalTime();
string clTimeZoneKey = TimeZone.CurrentTimeZone.StandardName;
TimeZoneInfo clTimeZone = TimeZoneInfo.FindSystemTimeZoneById(clTimeZoneKey);
DateTime clDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, clTimeZone);
if (clTimeZone.IsDaylightSavingTime(localDateTime))
{
// Get DayLight local time in UTC
// Yet to be implemented
}
return clDateTime.TimeOfDay;
}
I got this worked using this
http://msdn.microsoft.com/en-us/library/system.globalization.daylighttime.aspx
Ummm...we are currently using Daylight Saving Time in most of the U.S. (though there are some portions of Indiana that did/do use EST?) Since EDT is one hour ahead of EST, your logic is correct. It is the input (EST) that is incorrect.

Resources