<commit_before>from django.contrib.auth.models import *
from django.contrib.auth.backends import ModelBackend
from django.utils.translation import ugettext_lazy as _
from OctaHomeCore.basemodels import *
from OctaHomeCore.authmodels import *

import string
import random
import hashlib
import time

from authy.api import AuthyApiClient

#################
# Account Model #
#################
class DeviceUser(OctaBaseModel):
	User = models.ForeignKey('OctaHomeCore.CustomUser')
	Secret = models.CharField(max_length=30)
	
	def createDeviceSetupToken(self, host):
		self.Secret = ''.join(random.choice(string.ascii_uppercase) for i in range(30))
		self.save()
		return {"host":host, "user":self.id, "password":self.<PASSWORD> }
	
	def checkToken(self, token):
		salt = time.strftime("%H:%M-%d/%m/%Y")
		hashpassword = hashlib.sha512(self.Secret.encode('utf-8') + salt.encode('utf-8')).hexdigest().upper()
		if (hashpassword == token):
			return True
		else:
			return False
	<commit_msg>Update to make sure the auth date is on utc for time zone support on devices<commit_after>from django.contrib.auth.models import *
from django.contrib.auth.backends import ModelBackend
from django.utils.translation import ugettext_lazy as _
from OctaHomeCore.basemodels import *
from OctaHomeCore.authmodels import *

import datetime
import string
import random
import hashlib
import time

from authy.api import AuthyApiClient

#################
# Account Model #
#################
class DeviceUser(OctaBaseModel):
	User = models.ForeignKey('OctaHomeCore.CustomUser')
	Secret = models.CharField(max_length=30)
	
	def createDeviceSetupToken(self, host):
		self.Secret = ''.join(random.choice(string.ascii_uppercase) for i in range(30))
		self.save()
		return {"host":host, "user":self.id, "password":self.Secret }
	
	def checkToken(self, token):
		salt = datetime.datetime.utcnow().strftime("%H:%M-%d/%m/%Y")
		hashpassword = hashlib.sha512(self.Secret.encode('utf-8') + salt.encode('utf-8')).hexdigest().upper()
		if (hashpassword == token):
			return True
		else:
			return False
	
{'fraction_non_alphanumeric': 0.14997581035316884, 'fraction_numerical': 0.008708272859216255, 'mean_word_length': 5.50314465408805, 'pattern_counts': {'":': 6, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4866938', 'n_tokens_mistral': 686, 'n_tokens_neox': 642, 'n_words': 153}