Ejemplo n.º 1
0
        public HttpResponseMessage Post(Credentials credentials)
        {
            Student stud = db.Students.FirstOrDefault(s => s.EMail == credentials.EMail && s.Password == credentials.Password);
            if (stud == null)
            {
                return Request.CreateResponse(HttpStatusCode.Forbidden);
            }
            stud.TimeOfLastAction = DateTime.Now;

            string loginToken = GetSha512Hash(stud.EMail + stud.TimeOfLastAction + stud.Password);
            stud.SessionHash = loginToken;

            db.SaveChanges();

            List<string> responseList = new List<string>();
            responseList.Add(stud.EMail);
            responseList.Add(stud.SessionHash);

            return Request.CreateResponse(HttpStatusCode.OK, responseList);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post(Credentials credentials)
        {
            Professor prof = db.Professors.FirstOrDefault(p => p.EMail == credentials.EMail && p.Password == credentials.Password);
            if (prof == null)
            {
                return Request.CreateResponse(HttpStatusCode.Forbidden);
            }
            prof.TimeOfLastAction = DateTime.Now;

            string loginToken = GetSha512Hash(prof.EMail + prof.TimeOfLastAction + prof.Password);
            prof.SessionHash = loginToken;

            db.SaveChanges();

            List<string> responseList = new List<string>();
            responseList.Add(prof.EMail);
            responseList.Add(prof.SessionHash);

            return Request.CreateResponse(HttpStatusCode.OK, responseList);
        }