| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** Copyright (c) 1999, 2000, 2001, 2002, 2003 | 2 ** Copyright (c) 1999, 2000, 2001, 2002, 2003 |
| 3 ** Adel I. Mirzazhanov. All rights reserved | 3 ** Adel I. Mirzazhanov. All rights reserved |
| 4 ** | 4 ** |
| 5 ** Redistribution and use in source and binary forms, with or without | 5 ** Redistribution and use in source and binary forms, with or without |
| 6 ** modification, are permitted provided that the following conditions | 6 ** modification, are permitted provided that the following conditions |
| 7 ** are met: | 7 ** are met: |
| 8 ** | 8 ** |
| 9 ** 1.Redistributions of source code must retain the above copyright notice, | 9 ** 1.Redistributions of source code must retain the above copyright notice, |
| 10 ** this list of conditions and the following disclaimer. | 10 ** this list of conditions and the following disclaimer. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 ** randpass.c - Random password generation module of PWGEN program | 31 ** randpass.c - Random password generation module of PWGEN program |
| 32 */ | 32 */ |
| 33 | 33 |
| 34 #include <stdio.h> | 34 #include <stdio.h> |
| 35 #include <stdlib.h> | 35 #include <stdlib.h> |
| 36 #include <time.h> | 36 #include <time.h> |
| 37 #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32
__) | 37 #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32
__) |
| 38 #include <pwd.h> | 38 #include <pwd.h> |
| 39 #endif | 39 #endif |
| 40 #include <unistd.h> | 40 #include <unistd.h> |
| 41 |
| 42 #include "base/rand_util.h" |
| 43 #include "owntypes.h" |
| 41 #include "randpass.h" | 44 #include "randpass.h" |
| 42 | |
| 43 #include "owntypes.h" | |
| 44 #include "smbl.h" | 45 #include "smbl.h" |
| 45 | 46 |
| 46 /* | 47 /* |
| 47 ** gen_rand_pass - generates random password of specified type | 48 ** gen_rand_pass - generates random password of specified type |
| 48 ** INPUT: | 49 ** INPUT: |
| 49 ** char * - password string. | 50 ** char * - password string. |
| 50 ** int - minimum password length. | 51 ** int - minimum password length. |
| 51 ** int - maximum password length. | 52 ** int - maximum password length. |
| 52 ** unsigned int - password generation mode. | 53 ** unsigned int - password generation mode. |
| 53 ** OUTPUT: | 54 ** OUTPUT: |
| 54 ** int - password length or -1 on error. | 55 ** int - password length or -1 on error. |
| 55 ** NOTES: | 56 ** NOTES: |
| 56 ** none. | 57 ** none. |
| 57 */ | 58 */ |
| 58 int | 59 int |
| 59 gen_rand_pass (char *password_string, int minl, int maxl, unsigned int pass_mode
) | 60 gen_rand_pass (char *password_string, int minl, int maxl, unsigned int pass_mode
) |
| 60 { | 61 { |
| 61 int i = 0; | 62 int i = 0; |
| 62 int j = 0; | 63 int j = 0; |
| 63 int length = 0; | 64 int length = 0; |
| 64 char *str_pointer; | 65 char *str_pointer; |
| 65 int random_weight[94]; | 66 int random_weight[94]; |
| 66 int max_weight = 0; | 67 int max_weight = 0; |
| 67 int max_weight_element_number = 0; | 68 int max_weight_element_number = 0; |
| 68 | 69 |
| 69 if (minl > APG_MAX_PASSWORD_LENGTH || maxl > APG_MAX_PASSWORD_LENGTH || | 70 if (minl > APG_MAX_PASSWORD_LENGTH || maxl > APG_MAX_PASSWORD_LENGTH || |
| 70 minl < 1 || maxl < 1 || minl > maxl) | 71 minl < 1 || maxl < 1 || minl > maxl) |
| 71 return (-1); | 72 return (-1); |
| 72 for (i = 0; i <= 93; i++) random_weight[i] = 0; | 73 for (i = 0; i <= 93; i++) random_weight[i] = 0; |
| 73 length = minl + randint(maxl-minl+1); | 74 length = base::RandInt(minl, maxl); |
| 74 str_pointer = password_string; | 75 str_pointer = password_string; |
| 75 | 76 |
| 76 for (i = 0; i < length; i++) | 77 for (i = 0; i < length; i++) |
| 77 { | 78 { |
| 78 /* Asign random weight in weight array if mode is present*/ | 79 /* Asign random weight in weight array if mode is present*/ |
| 79 for (j = 0; j <= 93 ; j++) | 80 for (j = 0; j <= 93 ; j++) |
| 80 if ( ( (pass_mode & smbl[j].type) > 0) && | 81 if ( ( (pass_mode & smbl[j].type) > 0) && |
| 81 !( (S_RS & smbl[j].type) > 0)) | 82 !( (S_RS & smbl[j].type) > 0)) |
| 82 » random_weight[j] = 1 + randint(20000); | 83 random_weight[j] = base::RandInt(1, 20000); |
| 83 j = 0; | 84 j = 0; |
| 84 /* Find an element with maximum weight */ | 85 /* Find an element with maximum weight */ |
| 85 for (j = 0; j <= 93; j++) | 86 for (j = 0; j <= 93; j++) |
| 86 if (random_weight[j] > max_weight) | 87 if (random_weight[j] > max_weight) |
| 87 { | 88 { |
| 88 max_weight = random_weight[j]; | 89 max_weight = random_weight[j]; |
| 89 max_weight_element_number = j; | 90 max_weight_element_number = j; |
| 90 } | 91 } |
| 91 /* Get password symbol */ | 92 /* Get password symbol */ |
| 92 *str_pointer = smbl[max_weight_element_number].ch; | 93 *str_pointer = smbl[max_weight_element_number].ch; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 118 int max_weight = 0; | 119 int max_weight = 0; |
| 119 int max_weight_element_number = 0; | 120 int max_weight_element_number = 0; |
| 120 | 121 |
| 121 for (j = 0; j <= 93; j++) random_weight[j] = 0; | 122 for (j = 0; j <= 93; j++) random_weight[j] = 0; |
| 122 str_pointer = symbol; | 123 str_pointer = symbol; |
| 123 j = 0; | 124 j = 0; |
| 124 /* Asign random weight in weight array if mode is present*/ | 125 /* Asign random weight in weight array if mode is present*/ |
| 125 for (j = 0; j <= 93 ; j++) | 126 for (j = 0; j <= 93 ; j++) |
| 126 if ( ( (mode & smbl[j].type) > 0) && | 127 if ( ( (mode & smbl[j].type) > 0) && |
| 127 !( (S_RS & smbl[j].type) > 0)) | 128 !( (S_RS & smbl[j].type) > 0)) |
| 128 » random_weight[j] = 1 + randint(20000); | 129 random_weight[j] = base::RandInt(1, 20000); |
| 129 j = 0; | 130 j = 0; |
| 130 /* Find an element with maximum weight */ | 131 /* Find an element with maximum weight */ |
| 131 for (j = 0; j <= 93; j++) | 132 for (j = 0; j <= 93; j++) |
| 132 if (random_weight[j] > max_weight) | 133 if (random_weight[j] > max_weight) |
| 133 { | 134 { |
| 134 max_weight = random_weight[j]; | 135 max_weight = random_weight[j]; |
| 135 max_weight_element_number = j; | 136 max_weight_element_number = j; |
| 136 } | 137 } |
| 137 /* Get password symbol */ | 138 /* Get password symbol */ |
| 138 *str_pointer = smbl[max_weight_element_number].ch; | 139 *str_pointer = smbl[max_weight_element_number].ch; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 154 int | 155 int |
| 155 is_restricted_symbol (char symbol) | 156 is_restricted_symbol (char symbol) |
| 156 { | 157 { |
| 157 int j = 0; | 158 int j = 0; |
| 158 for (j = 0; j <= 93 ; j++) | 159 for (j = 0; j <= 93 ; j++) |
| 159 if (symbol == smbl[j].ch) | 160 if (symbol == smbl[j].ch) |
| 160 if ((S_RS & smbl[j].type) > 0) | 161 if ((S_RS & smbl[j].type) > 0) |
| 161 return(1); | 162 return(1); |
| 162 return(0); | 163 return(0); |
| 163 } | 164 } |
| OLD | NEW |