5
5
#include <notification/notification_messages.h>
6
6
#include <stdlib.h>
7
7
#include <passgen_icons.h>
8
+ #include <core/string.h>
8
9
9
10
#define PASSGEN_MAX_LENGTH 16
10
- #define PASSGEN_CHARACTERS_LENGTH (26 * 4)
11
11
12
12
#define PASSGEN_DIGITS "0123456789"
13
13
#define PASSGEN_LETTERS_LOW "abcdefghijklmnopqrstuvwxyz"
14
14
#define PASSGEN_LETTERS_UP "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
15
- #define PASSGEN_SPECIAL "!#$%^&*.-_"
15
+ #define PASSGEN_SPECIAL "!#$%% ^&*.-_"
16
16
17
17
typedef enum PassGen_Alphabet {
18
18
Digits = 1 ,
@@ -45,7 +45,8 @@ typedef struct {
45
45
FuriMutex * * mutex ;
46
46
NotificationApp * notify ;
47
47
char password [PASSGEN_MAX_LENGTH + 1 ];
48
- char alphabet [PASSGEN_CHARACTERS_LENGTH + 1 ];
48
+ // char alphabet[PASSGEN_CHARACTERS_LENGTH + 1];
49
+ FuriString * alphabet ;
49
50
int length ;
50
51
int level ;
51
52
} PassGen ;
@@ -57,6 +58,7 @@ void state_free(PassGen* app) {
57
58
furi_message_queue_free (app -> input_queue );
58
59
furi_mutex_free (app -> mutex );
59
60
furi_record_close (RECORD_NOTIFICATION );
61
+ furi_string_free (app -> alphabet );
60
62
free (app );
61
63
}
62
64
@@ -98,17 +100,17 @@ static void render_callback(Canvas* canvas, void* ctx) {
98
100
99
101
void build_alphabet (PassGen * app ) {
100
102
PassGen_Alphabet mode = AlphabetLevels [app -> level ];
101
- app -> alphabet [0 ] = '\0' ;
102
- if ((mode & Digits ) != 0 ) strcat (app -> alphabet , PASSGEN_DIGITS );
103
- if ((mode & Lowercase ) != 0 ) strcat (app -> alphabet , PASSGEN_LETTERS_LOW );
104
- if ((mode & Uppercase ) != 0 ) strcat (app -> alphabet , PASSGEN_LETTERS_UP );
105
- if ((mode & Special ) != 0 ) strcat (app -> alphabet , PASSGEN_SPECIAL );
103
+ if ((mode & Digits ) != 0 ) furi_string_cat (app -> alphabet , PASSGEN_DIGITS );
104
+ if ((mode & Lowercase ) != 0 ) furi_string_cat (app -> alphabet , PASSGEN_LETTERS_LOW );
105
+ if ((mode & Uppercase ) != 0 ) furi_string_cat (app -> alphabet , PASSGEN_LETTERS_UP );
106
+ if ((mode & Special ) != 0 ) furi_string_cat (app -> alphabet , PASSGEN_SPECIAL );
106
107
}
107
108
108
109
PassGen * state_init () {
109
110
PassGen * app = malloc (sizeof (PassGen ));
110
111
app -> length = 8 ;
111
112
app -> level = 2 ;
113
+ app -> alphabet = furi_string_alloc ();
112
114
build_alphabet (app );
113
115
app -> input_queue = furi_message_queue_alloc (8 , sizeof (InputEvent ));
114
116
app -> view_port = view_port_alloc ();
@@ -124,10 +126,10 @@ PassGen* state_init() {
124
126
}
125
127
126
128
void generate (PassGen * app ) {
127
- int hi = strlen (app -> alphabet );
129
+ int hi = furi_string_size (app -> alphabet );
128
130
for (int i = 0 ; i < app -> length ; i ++ ) {
129
131
int x = rand () % hi ;
130
- app -> password [i ] = app -> alphabet [ x ] ;
132
+ app -> password [i ] = furi_string_get_char ( app -> alphabet , x ) ;
131
133
}
132
134
app -> password [app -> length ] = '\0' ;
133
135
}
0 commit comments