apply FSL license
[pkgs/p/phone-lock.git] / phone-lock-common / src / phone-lock-verification.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   * 
4   * Licensed under the Flora License, Version 1.0 (the License);
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   * 
8   *     http://www.tizenopensource.org/license
9   * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an AS IS BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22
23 #include <security-server.h>
24
25 #include "phone-lock-util.h"
26 #include "phone-lock-verification.h"
27 #include "phone-lock-string.h"
28
29 #ifndef TRUE
30 #define TRUE 1
31 #define FALSE 0
32 #endif
33
34 int phone_lock_verification_check_length(const char *str, int min, int max)
35 {
36         int len = 0;
37
38         if (!str) {
39                 return IDS_IDLE_BODY_PASSWORD_EMPTY;
40         }
41
42         len = strlen(str);
43
44         PHONE_LOCK_DBG("%s() len : %d", __FUNCTION__, len);
45
46         if (len == 0) {
47                 return IDS_IDLE_BODY_PASSWORD_EMPTY;
48         }
49
50         if (len < min || len > max) {
51                 return IDS_IDLE_BODY_PD_TO_PD_DIGITS_OR_LETTERS_REQUIRED;
52         }
53
54         return 0;
55 }
56
57 int phone_lock_verification_check_phone_password(const char *str)
58 {
59         PHONE_LOCK_DBG("%s : %s\n", __FUNCTION__, str);
60
61         int ret = SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH;
62
63         unsigned int current_attempt = 0;
64         unsigned int max_attempt = 0;
65         unsigned int valid_secs = 0;
66
67         ret = security_server_chk_pwd(str, &current_attempt, &max_attempt, &valid_secs);
68         if (SECURITY_SERVER_API_SUCCESS == ret) {
69                 PHONE_LOCK_DBG("correct password!");
70                 return TRUE;
71         } else {
72                 return FALSE;
73         }
74 }